图像中的像素总数 [英] Total Number of pixels in an image
问题描述
如何获取图像(785x728)图像中的像素总数.我在这里应用了循环,这需要很多时间.任何简单的方法
How to get the total number of pixel in an image (785x728) image. I have applied loops here and it is taking lot of time. Any easy way
for i=1:height
for j=1:width
for d=1:colorChannel
value = double(rgbImage(i,j,d));
display(i);
totalSum = totalSum + value;
display(totalSum);
end
end
end
推荐答案
像素总数不等于图像中值的总和.
The total number of pixels is not equal to the sum of values in your image.
sumOfAllPixelValues = sum(double(rgbImage(:)));
numberOfPixels = numel(rgbImage);
图像在磁盘上的大小为numberOfPixels*bytesPerPixel
,其中bytesPerPixel
取决于图像的位深(例如,uint8
为8位= 1字节.
The size on disk of an image is numberOfPixels*bytesPerPixel
, where bytesPerPixel
depends on the bit depth of an image (uint8
would be 8 bits=1 byte, for example.
要将图像下采样一半,您可以减小位深度(例如,从uint16
变为uint8
),也可以将像素数在高度和宽度上减小sqrt(2)
,例如使用
To downsample the image by half, you can either reduce the bit depth (e.g. going from uint16
to uint8
, or you reduce the number of pixels by sqrt(2)
in height and width, for example using imresize
.
这篇关于图像中的像素总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!