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.

回答(2 个)

Johannes Hougaard
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

Image Analyst
Image Analyst 2020-6-26
I'd put them into rows of a table.

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by