Issue
I would like to apply a thresholding operation to several grayscale images with different threshold values so that the output, which is displayed as a matplotlib plot, will be 15 or so different images with levels of threshold applied to each. The problem I am facing is that it only displays one image after it runs but if I say print(dst.shape)
in the loop it will print 15 image shapes.
I have tried putting the output dst
in a list so that I could access them by index dst[2]
but this returned an error.
maxValue = 255
dst = []
for thresh in range(0, 255, 51):
for img in imageB, imageG, imageR:
th, dst = cv2.threshold(img, thresh, maxValue, cv2.THRESH_BINARY)
#print(dst.shape)
#print(len(dst))
plt.imshow(dst)
What I am trying to achieve is 15 different images from the loop. Is this a matplotlib issue? Am I required to create a figure of a specific size then access each variable in the dst
list? If so, why when I print(len(dst))
does it only return the length of the rows in the image?
Solution
You could use a figure
with sub-plots, something like this:
fig = plt.figure()
step = 51
maxValue = 255
nrows = 3
ncols = maxValue // step
i = 1
for thresh in range(0, maxValue, step):
for img in imageB, imageG, imageR:
th, dst = cv2.threshold(img, thresh, maxValue, cv2.THRESH_BINARY)
fig.add_subplot(nrows, ncols, i)
plt.imshow(dst)
i = i + 1
About your question why when I print(len(dst)) does it only return the length of the rows in the image?, see for example this question.
Answered By - dms
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.