How can my outputs be assigned to each image that is being processed
조회 수: 1 (최근 30일)
이전 댓글 표시
I am processing around 168 images to get their perimeters, convex hulls, and get a ratio between those two. Here is my code:
for k = 27 : 194
jpgFileName = strcat('Slice_v2_', num2str(k), '.png');
if isfile(jpgFileName)
[X, cmap] = imread(jpgFileName);
else
fprintf('File %s does not exist.\n', jpgFileName);
end
RGB = ind2rgb(X,cmap);
gray_image = rgb2gray(RGB);
BW = imbinarize(gray_image);
comp = imcomplement(BW);
imshowpair(gray_image, comp, 'montage');
%figure(1) %used tat index i so old figures are not overwritten by new figures
%imshow(our_images)
stats = regionprops (comp,'Perimeter'); %this can change
allPerimeters = [stats.Perimeter];
convhulls = bwconvhull(comp);
imshowpair(convhulls, comp, 'montage');
stats1 = regionprops (convhulls,'Perimeter');
allPerimeters2 = [stats1.Perimeter];
sum1 = sum(allPerimeters);
sum2 = sum(allPerimeters2);
giratio = sum1/sum2;
end
I get "gi =" for each but they are not individually saved into the workspace, I see why that happens. Only the last slice is kept in the workspace. I want to be able to have all of the perimeters (I have a sum since I get a struct array of values becasue the image has multiple bodies, so I want to add them up) and thus distinguished as separate outputs in order to graph it. Each perimeter, convex hull and gi calculation assigned to each slice instead of just a raw calculation. like a gi1-gi168.
댓글 수: 0
답변 (2개)
Johannes Hougaard
2020년 6월 26일
I would assign the outputs either to a multidimensional struct:
output = repmat(struct("RGB",[],...
"grayimage",[],...
"BW",[],...
"comp",[],...
"stats",[], ...
"giratio",[]),168,1);
for k = ...
output(k).RGB = ind2rgb(X,cmap);
...
end
or in a struct per variable with a field for each image
for k = ...
RGB.(strtok(jpgFileName,'.')) = ind2rgb(X,cmap);
...
end
Depending on whether you like your outputs organized mainly per image or per variable
댓글 수: 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!