How to annotate border around original RGB image
Show older comments
So I have a RGB image with two tags, I have binarized the image, removed the noise so it is just the two tags remaining. I have used rangefilt to then extract the border of each tag.
I now want to place the borders of the tag back on the original RGB image, with the border lines having 2 different colours for each tag. I am unsure how to do this, I have tried to use bwboundaries but this is unable to give me the outcome I desire with just the different colour borders alone on top of the original image.
The code:
clear all;
close all;
clc;
RGB = imread('tagPhoto.bmp');
%Yellow Tag
yellowChannel1Min = 0.000;
yellowChannel1Max = 255.000;
yellowChannel2Min = 71.000;
yellowChannel2Max = 255.000;
yellowChannel3Min = 0.000;
yellowChannel3Max = 40.000;
yellowSliderBW = (RGB(:,:,1) >= yellowChannel1Min ) & (RGB(:,:,1) <= yellowChannel1Max) & ...
(RGB(:,:,2) >= yellowChannel2Min ) & (RGB(:,:,2) <= yellowChannel2Max) & ...
(RGB(:,:,3) >= yellowChannel3Min ) & (RGB(:,:,3) <= yellowChannel3Max);
yellowBW = yellowSliderBW;
yellowMorph = imclose(yellowBW, ones(25));
%Red Border
redChannel1Min = 71.000;
redChannel1Max = 255.000;
redChannel2Min = 0.000;
redChannel2Max = 41.000;
redChannel3Min = 0.000;
redChannel3Max = 54.000;
redSliderBW = (RGB(:,:,1) >= redChannel1Min ) & (RGB(:,:,1) <= redChannel1Max) & ...
(RGB(:,:,2) >= redChannel2Min ) & (RGB(:,:,2) <= redChannel2Max) & ...
(RGB(:,:,3) >= redChannel3Min ) & (RGB(:,:,3) <= redChannel3Max);
redBW = redSliderBW;
redSE = strel("rectangle",[5 4]);
redOpen = imopen(redBW, redSE);
redMorph = imclose(redOpen, ones(25));
unionBW = redMorph | yellowMorph;
border = rangefilt(unionBW);
Input Image:

Binarised Image & Removed Noise:

Image with just borders (want to put over Input Image with different colours):

2 Comments
Shaista K
on 7 Dec 2022
hi good day can you please tell me how to find the centroid and region props readin on both these tags?
% this is the mask that would be generated in the given code
% i'm just going to load a copy instead of pasting the entire thing again
unionBW = imread('union.png');
S = regionprops(unionBW,'area','centroid') % S is a struct of properties for all objects
vertcat(S.Area) % for example, show the areas
vertcat(S.Centroid) % for example, show the centroids
Accepted Answer
More Answers (0)
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

