2

I am attempting to focus stack several images but I keep receiving the error below. Why am I receiving this error and how should I fix it?

Any advice and code snippets on how to fix this problem would be greatly appreciated.

I have taken a look at this post but am still unsure of the meaning of this error in my scenario.

File "/Users/...", line 32, in stack maximum = abs_laps.max(axis=0)

File "/anaconda3/lib/python3.5/site-packages/numpy/core/_methods.py", line 26, in _amax return umr_maximum(a, axis, None, out, keepdims)

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

The stack method indicated in the error above is provided below and so is the stacker method.

def stacker(folder, num):
    images = []
    for filename in os.listdir(folder):
        img = cv2.imread(os.path.join(folder,filename))
        if img is not None:
            images.append(img)
    stacked = stack(images)
    newpath = "key-frames" #destination of final image
    os.chdir(newpath)
    cv2.imwrite("Stacked%d.png" % num, stacked)

The stack method is below

def stack(imgs):
    #aligns the images
    images = imageAlignment(imgs)
    laps = []

    #loop through images and compute lap
    for i in range(len(images)):
        grayImg = cv2.cvtColor(images[i],cv2.COLOR_BGR2GRAY)
        laps.append(findLap(grayImg))

    #converts input to array
    laps = np.asarray(laps)

    #creates empty array
    output = np.zeros(shape=images[0].shape, dtype=images[0].dtype)

    #find absolute value of laps
    abs_laps = np.absolute(laps)

    #find maximum of laps
    maximum = abs_laps.max(axis=0)

    #boolean to determine if lap for image is max
    booleanChecker = abs_laps == maximum

    #pixels are unit8 and uint8 will wrap
    mask = booleanChecker.astype(np.uint8)

    #inverts every bit of array using mask that specifies of output array 
    #to be changed
    for i in range(0,len(images)):
        output = cv2.bitwise_not(images[i],output, mask=mask[i])

    return 255 - output

EDIT

Below is a sample of what abs_laps is made of.

[0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 2.000e+00 1.600e+01 6.400e+01 1.800e+02 >3.800e+02]

6
  • 1
    Provide minimal reproducible example please. Commented Jun 29, 2018 at 0:24
  • related post. Commented Jun 29, 2018 at 0:35
  • Can you show us what abs_laps looks like? Describe its shape and what's in it, or print it out? Commented Jun 29, 2018 at 0:37
  • 1
    @JayCalamari It is list of all the absolute values of laps that is 26 by 540 array. Commented Jun 29, 2018 at 2:06
  • 1
    @JayCalamari I have added a sample of what it looks like as an edit. Commented Jun 29, 2018 at 2:10

1 Answer 1

2

There is an error in your input data. You should print out on which image the code breaks and inspect the data. Most likely you have an empty image in the set of images to stack.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.