Detecting the position of a previously colored rectangle in an image
Show older comments
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
Accepted Answer
More Answers (1)
Gopichandh Danala
on 18 Apr 2018
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');

Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!