Clear Filters
Clear Filters

What is the function of flag?

95 views (last 30 days)
waffle
waffle on 21 Apr 2017
Commented: Walter Roberson on 10 May 2017
Hi,I want to find edge abruptness in melanoma but I dont know what is the function of flag in this coding..can u help me

Answers (3)

Image Analyst
Image Analyst on 22 Apr 2017
It appears to be some kind of way to get a mask of the background with smoothed borders. I agree with Walter that it's poorly written code and should be rewritten.
  4 Comments
Image Analyst
Image Analyst on 22 Apr 2017
Give a definition for "edge abruptness", because I'm not confident that that code is computing it as it should, but I don't know the formula for it. I'm guessing you have some paper that defines what it is.
waffle
waffle on 25 Apr 2017
This is the definition according to some paper

Sign in to comment.


Walter Roberson
Walter Roberson on 23 Apr 2017
To interpret the code, imagine a 2 x 2 matrix of binary values, and that you are focusing your attention on the upper left corner. Then
if(flag==1||flag==2||flag==4||flag==8) %true if exactly one of the four pixels is set
elseif (flag==3||flag==10||flag==12||flag==5) %true if two pixels in a row or column are set
elseif (flag==9||flag==6) %true if two pixels on a diagonal are set
elseif (flag==11||flag==14||flag==13||flag==7) %true if three pixels are set
and the code has no case for the situation where none of the pixels are set or all of the pixels are set.
You can use filter2 with [1 1;1 1] to count how many of the four pixels are set. To distinguish diagonals, you can filter2 with [1 0; 0 1] and detect result 0 or 2 as indicating a diagonal.
The distance calculation code D(idx)=sqrt((i+0.5-mx)^2+(j+0.5-my)^2) is exactly the same on all of the branches, and calculates the distance to the centroid. That can be done for all of the points simultaneously instead of in a loop, after which the "no points set" and "all points set" cases can be removed before calculating the mean.
The one pixel and three pixel cases lead to the same addition of sqrt(2) to P, so distinct branches are not needed for the two.
You should be able to vectorize all the calculations.
  9 Comments
waffle
waffle on 10 May 2017
and i dont understand what is mean by idx? is that kmean clustering
Walter Roberson
Walter Roberson on 10 May 2017
P is being used as a running total of some kind of local distance measurement, with the possible distance contributions being e2 = 1 (for adjacent pixels in a straight line), or e1 = 1/sqrt(2) (for one isolated pixel set, or for 3 of the four pixels set), or e3 = sqrt(2) (for two diagonal pixels.) The code you show does not use P after it is calculated; perhaps there was more code later on, or perhaps it was being returned from the function for some reason.
idx is used as a running counter of the number of locations whose distance has been calculated and stored. Not all locations have distances stored, because the code does not store a distance if none of the four pixels are set, or if all four pixels are set.

Sign in to comment.


Rik
Rik on 21 Apr 2017
The answer can be found in the documentation (just type doc filter2).
"The filter2 function filters data by taking the 2-D convolution of the input X and the coefficient matrix H rotated 180 degrees. Specifically, filter2(H,X,shape) is equivalent to conv2(X,rot90(H,2),shape)."
So flag is the output of that filtering in some specific pixel.
  5 Comments
waffle
waffle on 25 Apr 2017
thank you so much for your help!

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!