Labelling edges in an image

조회 수: 5 (최근 30일)
Adam
Adam 2014년 11월 6일
편집: Adam 2014년 11월 7일
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일
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
Adam
Adam 2014년 11월 7일
편집: Adam 2014년 11월 7일
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개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by