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!