Clear Filters
Clear Filters

How can I detect line lies between two certain regions?

2 views (last 30 days)
I have matrix I and I want to detect and coloring the line ( or thin region) which has DN (4) and located between the region which has DN (0) and the region which has DN (3).
I =
0 0 0 0 4 4 3 3
0 0 0 4 4 3 3 2
0 0 4 4 3 2 2 2
0 4 4 3 3 2 2 3

Accepted Answer

Image Analyst
Image Analyst on 17 Mar 2020
Simply use
coloredLabels = label2rgb (I, 'hsv', 'k', 'shuffle'); % pseudo random color labels
Here is a full demo:
I =[...
0 0 0 0 4 4 3 3
0 0 0 4 4 3 3 2
0 0 4 4 3 2 2 2
0 4 4 3 3 2 2 3]
hFig = figure;
subplot(2, 1, 1);
imshow(I, [], 'InitialMagnification', 1600);
fontSize = 16;
title('I', 'FontSize', fontSize);
% colorize the matrix
coloredLabels = label2rgb (I, 'hsv', 'k', 'shuffle'); % pseudo random color labels
% coloredLabels is an RGB image. We could have applied a colormap instead.
subplot(2, 1, 2);
imshow(coloredLabels, 'InitialMagnification', 1600);
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
title('Colorized I', 'FontSize', fontSize);
hp = impixelinfo; % Show color as use mouses around over image.
  4 Comments
faten Ahmed
faten Ahmed on 17 Mar 2020
Edited: faten Ahmed on 18 Mar 2020
the previous image is the result, Thank you. But, I want the line only between the building roof (DN 3) and the black region (DN 0, it is the shadow of the building)
Note that, there are many lines have DN=4, but I wnat to detect the lines beside black region only.
Image Analyst
Image Analyst on 18 Mar 2020
Take the 3 region and the 0 region and dilate one of them and then AND them. Something like (untested)
region3 = imdilate(labeledImage == 3, true(3));
borderImage = region3 & (labeledImage == 0);
imshow(borderImage, []);

Sign in to comment.

More Answers (1)

darova
darova on 17 Mar 2020
  • imbinarize image
  • use bwareaopen to clear a bit
  • use edge

Categories

Find more on Image Processing Toolbox 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!