After carrying out texture segmentation techniques on an image and then applying a binary mask I am trying to create an if else statement that will label the figure as a fail if the pixel count for black pixels in binary mask is above 1?
1 view (last 30 days)
Show older comments
I am relatively new to this so New ideas are welcome, another way around this may be to have a function that will scan through the binary image pixel by pixel and if it picks up black pixels then how will I create an if else statement to label or have a print function saying picture equals 'FAIL'??
Here is my code:
I = imread('CYMDK_ABS.jpg') //read image in//
%figure, imshow(I) // display initial image//
E = entropyfilt(I) // apply entropy filter//
Eim = mat2gray(E) // scale it down to a double image//
imshow(Eim) // show updated image//
BW1 = im2bw(Eim, .3) // apply binary mask with threshold value .3//
defect = true // define variable defect//
count = 0 // define counter //
if count>1
[row col]=find(BW1==0) // this function returns all pixels equal to 0//
defect = true
else defect = false
count = count + 1
end
%imshow(BW1)
0 Comments
Accepted Answer
Image Analyst
on 14 Nov 2013
It's not a very useful binary image if it must be all completely white. But anyway, to detect if there is a black pixel somewhere in the image:
if any(~BW1(:))
% At least one pixel is black.
end
2 Comments
Image Analyst
on 15 Nov 2013
any() looks at the image and processes each column, like many MATLAB functions such as sum(), etc. To avoid getting an array of numbers (one for each column) I turn the 2D array into a 1D array by using (:). Then any() checks to see if there is any pixel in that 1D array that is non-zero. Inverting it will tell you if there is at least one pixel that is exactly zero.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!