3

たとえば、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) 画像でのみ機能します。しかし、グレースケール画像からピクセル値を抽出したいと考えていますIfor次のようにループを使用してそうすることができます

for i = 1:size(coords,1)
    pixelData(i,:) = I(coords(i,2), coords(i,1));
end

forループの使用は避けたいと思います。これを達成する別の方法はありますか?

imstats = regionprops(mask, I,'PixelValues');も機能しますが、mask最初に画像が必要です。

4

2 に答える 2

5

を使用しsub2indます。

pixelData = I(sub2ind(size(I), coords(:,2), coords(:,1)));
于 2012-05-25T16:10:38.633 に答える
-3
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    
   }
}
于 2014-09-26T06:24:02.150 に答える