-1

約300の重心点のリストがあります。これらの点は、私が持っている BW 画像の conncomp の重心です。元のRGB画像の上に重心の点をプロットする方法はありますか?

4

1 に答える 1

0

問題ない。次の短いスクリプトを用意します。

img = imread('rice.png');
bg = imopen(img,strel('disk',15));
img2 = img - bg;

mask = im2bw(img2, 0.19);
mask = bwareaopen(mask, 40);

cc = bwconncomp(mask, 4);
positionArray = regionprops(cc, {'Centroid'});
positionArray = struct2cell(positionArray);
positionArray = cellfun(@transpose, positionArray, 'UniformOutput',false);
positionArray = cell2mat(positionArray);

imshow(img);
hold on;
scatter(positionArray(1, :), positionArray(2, :), 200, 'g+');

必要に応じて、マーカーのサイズと形状を変更できます。この場合のポイントは、最初の行に x 座標、2 番目の行に y を持つ 2 行 n 列の行列として格納されます。

まず、画像自体が imshow を使用してプロットされます。次に、scatter() が呼び出されます。両方のアイテムを同じ軸セットに配置するには、 hold on を呼び出す必要があります。

于 2013-08-02T20:15:13.157 に答える