【发布时间】:2012-06-01 05:39:58
【问题描述】:
比如说,我有一个 RGB 图像rgb 和一个空间坐标列表coords。我想提取空间坐标处的像素值,例如[x1 y1]、[x2 y2] 和[x3 y3]。对于 RGB 图像,我可以这样做:
rgb = imread('sample.jpg')
coords = [x1 y1; x2 y2; x3 y3];
pixelData = impixel(rgb, coords(:,1), coords(:,2));
返回指定图像像素的红色、绿色和蓝色值。
impixel 仅适用于彩色 (RGB) 图像。但我想从灰度图像I 中提取像素值。我可以使用for 循环来做到这一点,如下所示
for i = 1:size(coords,1)
pixelData(i,:) = I(coords(i,2), coords(i,1));
end
我想避免使用for 循环。有没有其他方法可以做到这一点?
imstats = regionprops(mask, I,'PixelValues'); 也可以,但我首先需要一张图片mask。
【问题讨论】: