how to write looping for certain area determine
1 view (last 30 days)
Show older comments
mohd akmal masud
on 19 Nov 2023
Commented: Walter Roberson
on 21 Nov 2023
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 Comments
Accepted Answer
Walter Roberson
on 19 Nov 2023
Moved: Walter Roberson
on 19 Nov 2023
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 Comments
Walter Roberson
on 21 Nov 2023
% 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
More Answers (0)
See Also
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!