what does count pixel =0 indicates?

After I applied stretching method and try to find threshold I got zero at count pixels as shown in image , what does it means and it happens only when I used png format or tif, while jpg I got concve curve for threshold.
My model is working well even with this fixed line but I want know why it happens and what does it means?

回答(2 个)

DGM
DGM 2023-7-14
编辑:DGM 2023-7-14
I don't know what app this is, and I don't know what the image is or how it has been processed, so I'm going to have to assume some things.
  1. I assume that the thresholding is not inclusive of the specified lower boundary (i.e. >, not >=)
  2. I assume that the image is binarized full-scale uint8
Given #2, all pixels should be either 0 or 255. There should be zero pixels which are between (but not equal to) the specified thresholds, so the result should be black.
The reason the JPG image gives results is because it has damaged the image.
Even if the image is not strictly binarized, JPG will still alter values, leading to different results.
If my assumptions are incorrect, feel free to clarify.

2 个评论

Ah. Then the lower test is inclusive of 0. I didn't notice that was an empty histogram. I don't know how OP would get that, even from an improperly-scaled image.

请先登录,再进行评论。

Image Analyst
Image Analyst 2023-7-14
It looks like your input image is practically binary already, because there is no histogram shown in the plot. Is it already binary? If so, you don't want to threshold it again. What is the input image's class? Logical, uint8, or double? Regardless the histogram y axis should show something, not -1 to 1.
Please attach the image just before you pass it in to my thresholding program so I can check to make sure everything is working normally. The app should work with any class of variable, e.g. uint8, double, etc.

12 个评论

@yasmin ismail When you save the test image, it will probably be best to save it as a .mat file so that the class and scale are preserved exactly as you see them. That information may be relevant to troubleshooting.
save('testimg.mat','myimagevariablename')
@Image Analyst I attached the binary image if you can check it please
@DGM yes the image is binary image and I saved it as png
if i save as you mentioned
save('testimg.mat','myimagevariablename')
how to use it as input image
When I suggested saving as a .mat file, that wasn't intended as a suggestion for your image processing routine, but merely as a means of allowing us to inspect the array as it exists in memory. Depending on the class and scale of the array, it may be altered when saved in standard image formats.
@Image Analyst I attached the binary image if you can check it please
Yep, it looks like a binary image. Not sure why you're refusing everyone's request to save the variable to a .mat file and upload the .mat file.
whos -file stretched_Image
Name Size Bytes Class Attributes stretched_Image 798x808x3 1934352 uint8
load stretched_Image
counts = histcounts(stretched_Image, 0:255);
counts = counts(:);
mask = counts ~= 0;
[find(mask) - 1, counts(mask)]
ans = 74×2
0 4317 1 339 2 279 3 339 4 330 5 252 6 318 7 267 8 222 9 222
Not a binary image.
imshow(stretched_Image); title('original')
stretched_Image(stretched_Image == 255) = 0;
imshow(stretched_Image); title('places that are not 0 or 255')
This was probably stored as a JPG image at some point. JPEG images damage edges.
can you please expalin your codes
counts = histcounts(stretched_Image, 0:255);
counts = counts(:);
mask = counts ~= 0;
[find(mask) - 1, counts(mask)]
@yasmin ismail see this commented code:
% Get histogram of image for gray levels 0 through 255
counts = histcounts(stretched_Image, 0:255);
% Turn counts into a column vector
counts = counts(:);
% Get a logical vector of what gray levels have non-zero counts (pixels exist with that gray level).
mask = counts ~= 0;
% Display in the command window the gray levels that have zero counts, plus their counts.
% We have to subtract 1 because the indexes go from 1-256 but the gray levels go from 0-255.
[find(mask) - 1, counts(mask)]
Does that help?
and this comment to binarize the image
stretched_Image(stretched_Image == 255) = 0;
?
That creates a logical image of where stretched_Image equals 255 and then it sets all those pixel locations to a value of 0.
Again, never save images to JPG, as Walter said, because it corrupts the image and generates noisy artifacts.
Not sure what "stretched" means but if you did something like imadjust before continuing to process the image, that is almost always unneeded and just slows down the process. If you do something like binarize the image, the threshold will be found and the image will get binarized correctly regardless if you stretched the contrast or not, so might as well save time and not do it.

请先登录,再进行评论。

移动:

2023-7-31

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by