Hi, everyone.. can someone help me? I'm still newbie and I'm doing task about segmentation using triclass thresholding but I got confused on the iteration process because TBD area must updated on each iteration. Here the algorithm : 1) Input image 2) find threshold using otsu method 3) divide into 2 area based on threshold (e.g : R1<= T, and R2>T) 4) calculate the mean of R1 and R2 (e.g : miu1 and miu2) 5) divide into 3 class : Background is less than miu1 TBD is between miu1 and miu2 Foreground is more than miu2 6) display TBD 7) do step 2-6 until new threshold same as the previous threshold *Note : the last TBD divide into 2 class (background<=T, foreground>T) can someone help me how to coding the iteration process? thank you

2 Kommentare

Ifah Muslimah
Ifah Muslimah am 20 Jun. 2017
Bearbeitet: Ifah Muslimah am 20 Jun. 2017
No, I just want to know how to coding the iteration process of segmentation using triclass thresholding algorithm above. for the example :
file='rice.png';
I=imread(file);
I2=im2uint8(I(:));
T1=graythresh(I2);
Th1=uint8(255*T1);
1st iteration
r1=I2 (I2<Th1);
r2=I2 (I2>=Th1);
miu1=uint8(mean2(r1));
miu2=uint8(mean2(r2));
TBD1=I2 (I2>=miu1 & I2<miu2);
B1=I2 (I2<miu1);
F1=I2 (I2>=miu2);
T2=graythresh(TBD1);
Th2=uint8(255*T2);
2nd iteration
r1=TBD1 (TBD1<Th2);
r2=TBD1 (TBD1>=Th2);
miu1=uint8(mean2(r1));
miu2=uint8(mean2(r2));
TBD2=TBD1 (TBD1>=miu1 & TBD1<miu2);
B2=TBD1 (TBD1<miu1);
F2=TBD1 (TBD1>=miu2);
T3=graythresh(TBD2);
Th3=uint8(255*T3);
3rd iteration
r1=TBD2 (TBD2<Th3);
r2=TBD2 (TBD2>=Th3);
miu1=uint8(mean2(r1));
miu2=uint8(mean2(r2));
TBD3=TBD2 (TBD2>=miu1 & TBD2<miu2);
B3=TBD2 (TBD2<miu1);
F3=TBD2 (TBD2>=miu2);
T4=graythresh(TBD3);
Th4=uint8(255*T4);
. . . the iteration process stop when the new T is same with the previous T (e.g : if the iteration stop at iteration 3, it's mean T4=T3
how to code this iteration code using "for" or "while" ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 20 Jun. 2017
Bearbeitet: Jan am 20 Jun. 2017

0 Stimmen

file = 'rice.png';
I = imread(file);
TBD = im2uint8(id(:));
T = graythresh(I2);
Th = uint8(255*T1);
T2 = T;
while max(abs(T(:) - T2(:)) > Limit
T = T2;
r1 = I2(TBD<Th);
r2 = I2(TBD>=Th);
miu1 = uint8(mean2(r1));
miu2 = uint8(mean2(r2));
TBD = TBD(TBD>=miu1 & I2<miu2);
B1 = TBD(TBD<miu1);
F1 = TBD(TBD>=miu2);
T2 = graythresh(TBD);
Th = uint8(255*T2);
end
Perhaps something like this with a suitable Limit to consider rounding effects?
This is untested code and I've edited it just by replacing the patterns in the names of the variables without understanding, what the code does.

Kategorien

Gefragt:

am 20 Jun. 2017

Bearbeitet:

am 20 Jun. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by