【问题标题】:MATLAB pixel values in gray scale images灰度图像中的 MATLAB 像素值
【发布时间】: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

【问题讨论】:

    标签: matlab image-processing


    【解决方案1】:

    使用sub2ind

    pixelData = I(sub2ind(size(I), coords(:,2), coords(:,1)));
    

    【讨论】:

      【解决方案2】:
      void Image::createImage(int width_x, int height_y)
      {
         pixelData = new Color* [width];  // array of Pixel*
      
         for (int x = 0; x < width; x++) 
         {
             pixelData[x] = new Color [height];  // this is 2nd dimension of pixelData    
         }
      }
      

      【讨论】:

        猜你喜欢
        • 2020-05-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-18
        • 1970-01-01
        • 2015-06-08
        • 2015-01-31
        • 2020-04-06
        相关资源
        最近更新 更多