How to get pixelcount in image.
35 views (last 30 days)
Show older comments
Deepika Rani
on 9 Dec 2016
Commented: Rukevwe Rim-Rukeh
on 25 Apr 2022
I tried with [pixel-count x]=imhist(i), i is gray scale image but I got pixel-count=256xdouble like dis not value. Please help me with this, matlab code.
0 Comments
Accepted Answer
Image Analyst
on 9 Dec 2016
i is the imaginary number and would be an especially horrible name for an image. Change it.
Your subject line says "How to get pixelcount in image." and the answer to that, for a gray scale image, is
numberOfPixels = numel(grayImage);
Then you say "[pixel-count x]=imhist(i)" Well pixel-count is not even a valid variable name. You can't have a minus sign in the middle of a variable name. Perhaps it was a type, like using "dis" for "this". Maybe you meant
[pixelCounts, grayLevels] = imhist(grayImage);
In that case pixelsCounts is the number of pixels in each gray level bin of the histogram, NOT the total number of pixels in the image, which would be the sum of the pixel counts in each bin:
numberOfPixels = sum(pixelCounts)
4 Comments
Rukevwe Rim-Rukeh
on 25 Apr 2022
Hello,
I want to find the number of pixels on the right handside or the left hand side of an image how do i do that
Thank you,
More Answers (1)
Guillaume
on 9 Dec 2016
What pixel count?
imhist returns the number of pixels at each of 256 different gray levels. If you want more or less intensity levels, simply specify a different number of bins rather than using the default.
If you want to know the total number of pixels in the image, it's simply height*width, i.e.
numpixels = size(i, 1) * size(i, 2); %and you shouldn't call your image i.
2 Comments
Guillaume
on 9 Dec 2016
This is the exact question I asked, what do you mean by pixel count? Pixel count of what?
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!