MATLAB: How to get pixelcount in image.

Image Processing Toolboximage segmentation

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.

Best Answer

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)