what does count pixel =0 indicates?
Afficher commentaires plus anciens
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?
Réponses (2)
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.
- I assume that the thresholding is not inclusive of the specified lower boundary (i.e. >, not >=)
- 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 commentaires
Image Analyst
le 14 Juil 2023
It's a screenshot of my interactive thresholding app:
DGM
le 14 Juil 2023
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
le 14 Juil 2023
0 votes
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 commentaires
@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')
yasmin ismail
le 14 Juil 2023
yasmin ismail
le 14 Juil 2023
Modifié(e) : yasmin ismail
le 14 Juil 2023
DGM
le 14 Juil 2023
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.
yasmin ismail
le 17 Juil 2023
Déplacé(e) : Voss
le 31 Juil 2023
Image Analyst
le 17 Juil 2023
Déplacé(e) : Voss
le 31 Juil 2023
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.
yasmin ismail
le 17 Juil 2023
Déplacé(e) : Voss
le 31 Juil 2023
Walter Roberson
le 17 Juil 2023
Déplacé(e) : Voss
le 31 Juil 2023
whos -file stretched_Image
load stretched_Image
counts = histcounts(stretched_Image, 0:255);
counts = counts(:);
mask = counts ~= 0;
[find(mask) - 1, counts(mask)]
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.
yasmin ismail
le 31 Juil 2023
Déplacé(e) : Voss
le 31 Juil 2023
Image Analyst
le 31 Juil 2023
Déplacé(e) : Voss
le 31 Juil 2023
@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?
yasmin ismail
le 31 Juil 2023
Déplacé(e) : Voss
le 31 Juil 2023
Image Analyst
le 31 Juil 2023
Déplacé(e) : Voss
le 31 Juil 2023
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.
Catégories
En savoir plus sur Image Type Conversion dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

