图像中的像素总数 [英] Total Number of pixels in an image

查看:79
本文介绍了图像中的像素总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取图像(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆