How to add a border around

2 views (last 30 days)
Eunoo Bak
Eunoo Bak on 7 Feb 2020
Answered: Image Analyst on 7 Feb 2020
I have two images like this. (image A, B)
I want to (1) overlap the figures and (2) fit a border around the areas of different color.
; as image C with 'red line around dark red area' and 'blue line around the light red area'.
I am unsure how to use the image proccessing toolbox to draw a borderline.
Image.png

Answers (1)

Image Analyst
Image Analyst on 7 Feb 2020
For each image, convert to hsv color space with rgb2hsv. Untested code follows. Adapt/fix as needed.
hsvImage1 = rgb2hsv(rgbImage1);
hsvImage2 = rgb2hsv(rgbImage2);
Then create binary masks by thresholding the s channel to get regions that are not pure gray.
sImage1 = hsvImage1(:, :, 2);
mask1 = sImage1 > 0;
sImage2 = hsvImage2(:, :, 2);
mask2 = sImage2 > 0;
Then call bwboundaries
boundaries1 = bwboundaries(mask1);
boundaries2 = bwboundaries(mask2);
Then blend the images however you want to do it, for example by taking the average or other ways.
blendedImage = uint8((double(rgbImage1) + double(rgbImage2))/2);
imshow(blendedImage);
Then plot the boundaries over the blended image:
% Plot boundaries1 over the image.
for k = 1 : length(boundaries1)
thisBoundary = boundaries1{k};
x = thisBoundary(:, 2);
y = thisBoundary(:, 1);
hold on;
plot(x, y, 'm-', 'LineWidth', 2);
end
% Repeat for boundaries2
% Plot boundaries2 over the image.
for k = 1 : length(boundaries2)
thisBoundary = boundaries2{k};
x = thisBoundary(:, 2);
y = thisBoundary(:, 1);
hold on;
plot(x, y, 'm-', 'LineWidth', 2);
end

Categories

Find more on Polar Plots 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!