How can I detect line lies between two certain regions?

2 次查看(过去 30 天)
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

采纳的回答

Image Analyst
Image Analyst 2020-3-17
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 个评论
faten Ahmed
faten Ahmed 2020-3-17
编辑:faten Ahmed 2020-3-18
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 2020-3-18
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, []);

请先登录,再进行评论。

更多回答(1 个)

darova
darova 2020-3-17
  • imbinarize image
  • use bwareaopen to clear a bit
  • use edge

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by