How to associate a rectangle with a struct?

1 回表示 (過去 30 日間)
Oliver Lestrange
Oliver Lestrange 2020 年 8 月 5 日
コメント済み: Walter Roberson 2020 年 8 月 7 日
Hi there Community,
I have the folllowing image and the antenna:
[Horizontal,Vertical,Optional] = msiread(strcat(pathName,fileName));
How can I associate a rectangle to an antenna?
I made the rectangle using:
rectangle('Position', [(x - handles.Rwidth/2) (y - handles.Rwidth/2)...
handles.Rwidth handles.Rheight], 'FaceColor', 'g','LineStyle', 'none');
Is it possible to affect the rectangule with the struct (antenna)?
  10 件のコメント
Adam Danz
Adam Danz 2020 年 8 月 6 日
So this is an image processing problem as Walter Roberson elluded to, correct?
Oliver Lestrange
Oliver Lestrange 2020 年 8 月 6 日
Yes

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2020 年 8 月 6 日
rgb = imread(filename) ;
mask = rgb(:, 1) < 32 & rgb(:, 2) > 224 & rgb(:, 3) > 224;
mask = bwareafilt(mask, [50 inf]);
props = regionprops(mask, 'centroid') ;
locations = vertcat(props.Centroid);
The constants in the above are not tested, only "by eye", and probably need to be adjusted.
The resulting variable will be a something by 2 array in which the first column is x and the second is y. Note that x corresponds to columns, second array index, and y corresponds to row, first index.
  4 件のコメント
Oliver Lestrange
Oliver Lestrange 2020 年 8 月 7 日
And why the < 32 and > 224 ? Where this numbers came from?
Walter Roberson
Walter Roberson 2020 年 8 月 7 日
Looks like I should have used
mask = rgb(:, :, 1) > 224 & rgb(:, :, 2) > 224 & rgb(:, :, 3) < 32;
as I was mistaken about the composition of yellow in RGB.
filename = 'image.png';
rgb = imread(filename) ;
mask = rgb(:, :, 1) > 200 & rgb(:, :, 2) > 200 & rgb(:, :, 3) < 32;
maskfilt = bwareafilt(mask, [50 inf]);
props = regionprops(maskfilt, 'centroid') ;
locations = vertcat(props.Centroid);
imshow(rgb)
hold on
scatter(locations(:,1), locations(:,2), 'r*')
hold off
The 32 and 224 came from my experience with RGB colors.
Your yellow blobs appear to be approximately "dark yellow 1". You can tell the values by imshow(rgb) and using the data cursor tool to read RGB values off of the image.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePhased Array Design and Analysis についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by