how to write looping for certain area determine
3 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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 个评论
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 Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!