how to write loop coding for dicom image.
조회 수: 3 (최근 30일)
이전 댓글 표시
Dear all,
i have image dicom (as attached) for SPECT machine. But in this image, there are 72 slice (frame) can see in dicominfo.
But when i want to apply adaptthresh to every image, i have to write as code below for every slice. So then i have to change the number slice every time.
%let say I want to know the slice number 38
I = dicomread('spect128x128', 'frame', 38);
%determine threshold
T = adaptthresh(I, 0.4);
%change grey to binary
BW = imbinarize(I,T);
%open image
figure
imshowpair(I, BW, 'montage')
CC = bwconncomp(BW)
[r, c] = cellfun(@(x) ind2sub(size(BW), x), CC.PixelIdxList, 'UniformOutput', 0)
T = regionprops('table', BW,'Area','Centroid')
My question is, how i want to write for the loop code for the first slice(frame) till last slice. So that i no need to change the number of slice every time, and adaptthresh can apply for all the slice.
Please help me.
댓글 수: 0
채택된 답변
Image Analyst
2020년 12월 6일
Try this:
for sliceIndex = 1 : numSlices
% Read this slice.
fprintf('Reading slice #%d...\n', sliceIndex);
thisImage = dicomread('spect128x128', 'frame', sliceIndex);
% Determine threshold
threshold = adaptthresh(thisImage, 0.4);
% Change grey to binary
BW = imbinarize(thisImage, threshold);
% Display images.
imshowpair(thisImage, BW, 'montage')
drawnow;
% CC = bwconncomp(BW);
% [r, c] = cellfun(@(x) ind2sub(size(BW), x), CC.PixelIdxList, 'UniformOutput', 0)
propTables{sliceIndex} = regionprops('table', BW, 'Area', 'Centroid')
end
댓글 수: 8
Image Analyst
2020년 12월 7일
No. Just one loop.
% Processes slices 43 through 46.
for sliceIndex = 43 : 46
% Read this slice.
fprintf('Reading slice #%d...\n', sliceIndex);
thisImage = dicomread('I-131101', 'frame', sliceIndex);
% Determine threshold
fprintf(' Getting threshold image...\n');
threshold = adaptthresh(thisImage, 0.4);
% Change grey to binary
fprintf(' Thresholding slice #%d\n', sliceIndex);
BW = imbinarize(thisImage, threshold);
% Display images.
figure
imshowpair(thisImage, BW, 'montage')
drawnow;
% Get the measurements for this one slice.
fprintf(' Making measurements via regionprops()...\n');
thisTable = regionprops('table', BW,'Area','Centroid');
% Append the table for this image onto the table for ALL images.
fprintf(' Appending measurements to table...\n');
if k == 1
% No table yet, so make the table for the first one the master one.
overallTable = thisTable;
else
% Overall table exists already so append thisTable onto that with vertcat().
overallTable = vertcat(overallTable, thisTable);
end
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!