Labelling edges in an image

I am trying to do what should be a really basic image processing task, but don't seem to be able to find a particular neat solution so hopefully someone can suggest one.
I simply wish to find the edges between three coloured segments of the image below as single-pixel thick lines with 3 distinct values representing the 3 different boundary possibilities. I don't care what the 3 distinct values are so long as they are distinct.
This is the solution I want (ignore the colourmap, I was just trying to find colours that made it easy to distinguish) - here the 3 values happen to be 3, 4, 5.
My method for achieving it was:
f = @(x) ( x(2) ~= x(1) ) * ( x(2) + x(1) );
edgeRes = nlfilter( wedge, [1 2], f );
i.e. basically just looking at a 1*2 window and adding together the two values in the window if they differ.
I don't like this solution much though as nlfilter throws up a progress bar (plus it feels like there should be a much simpler method).
The input data and the edge result I have should be in the attached .mat file if anyone has any better idea for achieving this seemingly trivial task!

 采纳的回答

Ahmet Cecen
Ahmet Cecen 2014-11-6

0 个投票

For this particular image and any image with a similar enough trivial nature, there is a very short solution: A is your image with 3 regions which are 1 2 and 4, use circshift to shift A left by 1 pixel, then add the shifted image with the original image. Now anywhere with a 3 is a 1 2 boundary, 5 is a 1 4 boundary 6 is a 2 4 boundary.

1 个评论

Thanks. After managing to do every part of your solution incorrectly at first (wrong circshift dimension, forgetting to use 4 instead of 3 for my 3rd region, etc) this gives me exactly what I want:
wedge( wedge == 3 ) = 4;
edgeRes = wedge + circshift( wedge, 1, 2 );
edgeRes(:,1) = 0;
edgeRes( isIntegerValued( log2( edgeRes ) ) ) = 0;
(isIntegerValued is my own function and seemed the neatest way of removing all the other values which I wish to be 0).

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File 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