I am trying to write code that will create mismatch maps using numpy and scipy, but the values โโthat I store in my numpy array for my images are completely different from the values โโthat actually appear on my output images are stored with misc.immave. For example, in the array, none of the values โโis greater than 22, but in the image I have a full range of values โโfrom 0 to 255. I thought that perhaps imsave stretches the values โโso that the maximum value is displayed as 255 in the image, but I have There are other images created with imsave that have a maximum below 255.
These are the functions that I use to create my mismatch maps, given the two pgm images that were shifted along the x axis:
def disp(i, j, winSize, leftIm, rightIm): #calculate disparity for a given point width = leftIm.shape[1] height = leftIm.shape[0] w = winSize / 2 minSAD = 9223372036854775807 #max int for d in range(23): SAD = 0.0 #SAD k = i - w v = i + w m = j - w n = j + w for p in range(k, v+1): #window - x for q in range(m, n+1): #window y if(p - d > 0 and p < width and q < height): SAD += abs((int(leftIm[q][p]) - int(rightIm[q][p - d]))) if(SAD < minSAD): minSAD = SAD disp = d # print "%d, %d" % (i, j) return (disp, SAD) def dispMap(winSize, leftIm, rightIm): width = leftIm.shape[1] height = leftIm.shape[0] outIm = np.zeros((height, width)) SADstore = np.zeros((height, width)) w = winSize / 2 for i in range(w, width-w): for j in range(w, height/3-w): dispout = disp(i, j, winSize, leftIm, rightIm) outIm[j][i] = 1 * dispout[0] #should normally multiply by 4 SADstore[j][i] = dispout[1] return (outIm, SADstore)
Ignore the returned SAD / SADstore values, I made sure that they do not affect my current process.
This is the code I use to get my output:
disp12 = dispMap(9, view1, view2) disp12im = disp12[0] misc.imsave('disp121.pgm', disp12im)
Like the current one, nothing in disp12im should be> 23. If I run a for loop to check this in the array, this will remain true. However, if I load the saved image and run the same for the loop for the values, I get tons of numbers over 23. What am I doing wrong?