フィルターのクリア

Detecting the position of a previously colored rectangle in an image

2 ビュー (過去 30 日間)
Maximilian Stopfer
Maximilian Stopfer 2018 年 4 月 18 日
コメント済み: Maximilian Stopfer 2018 年 4 月 24 日
Hello,
do you think I can use MatLab for detecting the position of a previously colored rectangle in an image? I am new at MatLab and currently thinking about if it is possible to use this software for my purpose. Do you know any similar projects or tutorials, which could help me further?
PS: I attached an example image, e. g. how can I get the position of all blue rectangles?
Best regards Max

採用された回答

Guillaume
Guillaume 2018 年 4 月 19 日

Since your image is indexed, with only 4 colours (0 = reddish, 1 = bluish, 2 = yellowish and 3 = white) it's actually trivial to detects the pixels of each colour:

[img, map] = imread('example.png');
bluepixels = img == 1;

You can then use regionprops to get the pixels, bounding box, perimeter, etc. of the rectangles:

props = regionprops(bluepixels, 'basic');  %will return the bounding box, area and centroid of each blue object.
  3 件のコメント
Guillaume
Guillaume 2018 年 4 月 19 日
編集済み: Guillaume 2018 年 4 月 19 日
The first thing to establish is whether all the images are indexed images, as your example is, or if some are rgb.
If they are all indexed, then the only thing you have to do is identify which index correspond to the colour you want. Is the colour palette that is used to create your images fixed?
Maximilian Stopfer
Maximilian Stopfer 2018 年 4 月 24 日

Update: following code works to 95%

ImA = imread('image.png');
ImA1 = 255 - ImA(:,:,1);
th = 0.98;
ImA2 = imbinarize(ImA1, th);
out = regionprops(ImA2);
writetable(struct2table(out), 'out.xlsx');

I changed my strategy and marked the specific areas (with a greyish background) just with green rectangles, then ran the code and exported it as an excel sheet. Since there are some non-sense values I want to add a filter to delete all values between two limits to exclude these values. But this is another task. Thank you for your help!

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

その他の回答 (1 件)

Gopichandh Danala
Gopichandh Danala 2018 年 4 月 18 日

You can use thresholding, I am using hsv to fo this.

[img, map] = imread('example.png');
if ~isempty(map)
    colorImg = ind2rgb(img,map);
end
% Convert RGB image to HSV
hsvImage = rgb2hsv(colorImg);
% Extract out the H, S, and V images individually
hImage = hsvImage(:,:,1);
sImage = hsvImage(:,:,2);
vImage = hsvImage(:,:,3);
% filter using hImage
filterImage = hImage > 0.6; % find this value from hImage
blueMap = imfill(filterImage,'holes');
figure, 
subplot(131), imshow(colorImg), title('Orig color image');
subplot(132), imshow(filterImage), title('Filtered image');
subplot(133), imshow(blueMap), title('Blue map image');

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by