Extract structure within cell structure
이전 댓글 표시
Hello,
I need help extracting structures of difference sizes from an array. I want to to extract the structure into variables that go like this: stats1, stats2, stats3, stats4 and so on. I can do this line by line, but when I try to do this on a loop (because there will be 100 images) matlab won't run the code. I attached the images that I am working with
clear;
clc;
% Importing PNG images
for k = 1:3
a{k} = sprintf('AB%d.png', k);
AB{k} = imread(a{k});
%spliting to RGB channels and image filtering
[r{k},BW{k},b{k}] = imsplit(AB{k});
BW{k}= imsharpen(BW{k});
BW{k}=im2bw(BW{k},0.15);
%imshow(BW{k})
% getting images Stats
stats{k}= regionprops(BW{k},"all");
end
%Below is what I need help creating a loop. This works fine, but I'd like
%to have a loop rather than writting the same line over and over
stats1 = stats(1,1);
stats1 = cell2mat(stats1);
stats2 = stats(1,2);
stats2 = cell2mat(stats2);
stats3 = stats(1,3);
stats3 = cell2mat(stats3);
%And so on... This code works for my needs, but I need a loop to create a new variable from stats1 to stats 3
%(there will be more images, like 100)
I had this in mind, but it is also a cell with structures
for i=1
stats1(i)= stats1(1,i);
end
댓글 수: 2
Stephen23
2022년 10월 3일
So far you have not given any reason why you need to force yourself into writing slow, complex, inefficient, buggy code which is hard to debug... when you already have a cell array (which you can trivially access using simple and efficient indexing):
"I had this in mind, but it is also a cell with structures"
Note that your loop does nothing.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!