How can my outputs be assigned to each image that is being processed
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Johannes Hougaard
on 26 Jun 2020
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 Comments
See Also
Categories
Find more on Image Processing Toolbox 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!