Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions FocusStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ def align_images(images):
detector = cv2.ORB_create(1000)

# We assume that image 0 is the "base" image and align everything to it
print "Detecting features of base image"
print("Detecting features of base image")
outimages.append(images[0])
image1gray = cv2.cvtColor(images[0],cv2.COLOR_BGR2GRAY)
image_1_kp, image_1_desc = detector.detectAndCompute(image1gray, None)

for i in range(1,len(images)):
print "Aligning image {}".format(i)
print("Aligning image {}".format(i))
image_i_kp, image_i_desc = detector.detectAndCompute(images[i], None)

if use_sift:
Expand Down Expand Up @@ -126,14 +126,14 @@ def doLap(image):
def focus_stack(unimages):
images = align_images(unimages)

print "Computing the laplacian of the blurred images"
print("Computing the laplacian of the blurred images")
laps = []
for i in range(len(images)):
print "Lap {}".format(i)
print("Lap {}".format(i))
laps.append(doLap(cv2.cvtColor(images[i],cv2.COLOR_BGR2GRAY)))

laps = np.asarray(laps)
print "Shape of array of laplacians = {}".format(laps.shape)
print("Shape of array of laplacians = {}".format(laps.shape))

output = np.zeros(shape=images[0].shape, dtype=images[0].dtype)

Expand All @@ -144,4 +144,4 @@ def focus_stack(unimages):
for i in range(0,len(images)):
output = cv2.bitwise_not(images[i],output, mask=mask[i])

return 255-output
return 255-output
10 changes: 5 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Focus stack driver program

This program looks for a series of files of type .jpg, .jpeg, or .png
in a subdirectory "input" and then merges them together using the
in a subdirectory "Input" and then merges them together using the
FocusStack module. The output is put in the file merged.png


Expand All @@ -19,19 +19,19 @@
def stackHDRs(image_files):
focusimages = []
for img in image_files:
print "Reading in file {}".format(img)
focusimages.append(cv2.imread("input/{}".format(img)))
print("Reading in file {}".format(img))
focusimages.append(cv2.imread("Input/{}".format(img)))

merged = FocusStack.focus_stack(focusimages)
cv2.imwrite("merged.png", merged)


if __name__ == "__main__":
image_files = sorted(os.listdir("input"))
image_files = sorted(os.listdir("Input"))
for img in image_files:
if img.split(".")[-1].lower() not in ["jpg", "jpeg", "png"]:
image_files.remove(img)


stackHDRs(image_files)
print "That's All Folks!"
print("That's All Folks!")