필터 지우기
필터 지우기

What is the function of flag?

조회 수: 95 (최근 30일)
waffle
waffle 2017년 4월 21일
댓글: Walter Roberson 2017년 5월 10일
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

답변 (3개)

Image Analyst
Image Analyst 2017년 4월 22일
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
Image Analyst
Image Analyst 2017년 4월 22일
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 2017년 4월 25일
This is the definition according to some paper

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2017년 4월 23일
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
waffle
waffle 2017년 5월 10일
and i dont understand what is mean by idx? is that kmean clustering
Walter Roberson
Walter Roberson 2017년 5월 10일
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.

댓글을 달려면 로그인하십시오.


Rik
Rik 2017년 4월 21일
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
waffle
waffle 2017년 4월 25일
thank you so much for your help!

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by