gpt4 book ai didi

MATLAB:查找图像中特定 rgb 像素值的索引/计数

转载 作者:行者123 更新时间:2023-12-02 05:42:47 25 4
gpt4 key购买 nike

我正在使用 matlab 获取图像中特定像素值的计数。

当读入 matlab 时,图像是 RGBA <512x512x4 uint8>(尽管我们可以忽略 alpha channel )。

除了;

[width, height, depth] = size(im);

for x = 1 : width;
for y = 1: height;

r = im(x,y,1);
g = im(x,y,2);
b = im(x,y,3);

...

end
end

有没有一种方法可以使用矩阵运算来做到这一点?类似的东西:

X = find(im(:,:,1) == 255 && im(:,:,2) == 255 && im(:,:,3) == 255);
count = length(X);
% Count being the number of pixels with RGB value (255,255,255) in the image.

我猜有不止几种方法可以做到这一点(查看相交,独特的功能),但我还不够聪明,无法使用 matlab 来做到这一点。有什么帮助吗?

最佳答案

其实很简单。像这样

count = sum(im(:, :, 1) == 255 & im(:, :, 2) == 255 & im(:, :, 3) == 255);

将为您提供此类像素的计数。如果需要,将 sum 替换为 find 以获取这些像素的索引。

关于MATLAB:查找图像中特定 rgb 像素值的索引/计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10723943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com