Filter löschen
Filter löschen

How can I detect line lies between two certain regions?

2 Ansichten (letzte 30 Tage)
faten Ahmed
faten Ahmed am 17 Mär. 2020
Kommentiert: Image Analyst am 18 Mär. 2020
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

Akzeptierte Antwort

Image Analyst
Image Analyst am 17 Mär. 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 Kommentare
faten Ahmed
faten Ahmed am 17 Mär. 2020
Bearbeitet: faten Ahmed am 18 Mär. 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 am 18 Mär. 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, []);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

darova
darova am 17 Mär. 2020
  • imbinarize image
  • use bwareaopen to clear a bit
  • use edge

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by