how to write looping for certain area determine

3 ビュー (過去 30 日間)
mohd akmal masud
mohd akmal masud 2023 年 11 月 19 日
コメント済み: Walter Roberson 2023 年 11 月 21 日
Dear all,
I wrote some script looping to determine the thresh value for certain Area (267). But I got error like below. The set imageas data set as attached.
Actually, my original script is like below:
seedR1 = 58; seedC1 = 76; seedP1 = 45;
W = graydiffweight(spect, seedC1, seedR1, seedP1, 'GrayDifferenceCutoff', 1000000000);
thresh =0.0001;
[BW, D] = imsegfmm (W, seedC1, seedR1, seedP1, thresh);
T = regionprops('table', BW,'Area','Centroid')
Area Centroid
____ __________________________
12 75.833 58.167 44.5
Then I have to change the thresh (try and error) until I got the Area is 267.
But I want to do something like looping or iteration, which is I set the Area is 267. Then wrote the script like below:
seedR1 = 58; seedC1 = 76; seedP1 = 45;
W = graydiffweight(spect, seedC1, seedR1, seedP1, 'GrayDifferenceCutoff', 1000000000);
for thresh =0.0001:0.0001:0.9999
[BW, D] = imsegfmm (W, seedC1, seedR1, seedP1, thresh);
T = regionprops('table', BW,'Area','Centroid');
if T{1,1}==267
gray_weight = thresh;
volume = T{1,1};
end
end
Can anyone help me?

採用された回答

Walter Roberson
Walter Roberson 2023 年 11 月 19 日
移動済み: Walter Roberson 2023 年 11 月 19 日
Have you considered using fzero or fsolve? Those could use slope information to zoom in on the appropriate thresh
The objective would be something along the lines of
accept parameter Th. Use it with the segmm. Regionprops to get the area. Return area minus 267.
fzero or fsolve would then supply trial thresholds and would search for one that made the function zero. The function is area minus 267 so a zero for the difference would be equivalent to having searched for the threshold that gave an area of 267
  9 件のコメント
mohd akmal masud
mohd akmal masud 2023 年 11 月 20 日
yah, I have tried the same problem.
% Read main set data
[spect map]=dicomread('I-131sphere10nisbah1.dcm');
info = dicominfo('I-131sphere10nisbah1.dcm');
%gp=info.SliceThickness;
spect=(squeeze(spect));%smooth3
Target_Volume = 26.67;
seedR1 = 58; seedC1 = 76; seedP1 = 45;
W = graydiffweight(spect, seedC1, seedR1, seedP1, 'GrayDifferenceCutoff', 1000000000);
fun = @(thresh)findvol(W, seedC1, seedR1, seedP1,thresh,Target_Volume);
[greyweight, residue] = fzero(fun, [0.0001, 0.01]);
volume = residue + Target_Volume;
greyweight
volume
function residue = findvol(W, seedC1, seedR1, seedP1, thresh, Target_Volume)
[BW, D] = imsegfmm (W, seedC1, seedR1, seedP1, thresh);
T = regionprops3(BW,'Volume');
residue = T.Volume(1) - Target_Volume;
end
Error using fzero
Function values at the interval endpoints must differ in sign.
But its ok. Thank you both of you sir because spent time to help me try to resolve my problem. Thank you so much. both you are awesome. :)
Walter Roberson
Walter Roberson 2023 年 11 月 21 日
% Read main set data
[spect map]=dicomread('I-131sphere10nisbah1.dcm');
info = dicominfo('I-131sphere10nisbah1.dcm');
%gp=info.SliceThickness;
spect=(squeeze(spect));%smooth3
Target_Volume = 26.67;
seedR1 = 58; seedC1 = 76; seedP1 = 45;
W = graydiffweight(spect, seedC1, seedR1, seedP1, 'GrayDifferenceCutoff', 1000000000);
fun = @(thresh)findvol(W, seedC1, seedR1, seedP1,thresh,Target_Volume);
nvars = 1;
A = []; b = []; Aeq = []; beq = []; lb = 0.0001; ub = 0.01; nonlcon = [];
gafun = @(thresh) fun(thresh).^2;
greyweight = ga(gafun, nvars, A, b, Aeq, beq, lb, ub, nonlcon);
residue = fun(greyweight);
volume = residue + Target_Volume;
greyweight
volume
function residue = findvol(W, seedC1, seedR1, seedP1, thresh, Target_Volume)
[BW, D] = imsegfmm (W, seedC1, seedR1, seedP1, thresh);
T = regionprops3(BW,'Volume');
residue = T.Volume(1) - Target_Volume;
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by