Reputation: 59
I am currently working on an image processing task that requires me to process a stack of .png images all at once in Matlab (I have very limited matlab knowledge). I have looked at various sites trying to figure out how to do this. My most recent attempt was based on the answer in this link: http://www.mathworks.com/matlabcentral/answers/7665-images-to-stacks, however I keep getting the error: "Assignment has more non-singleton rhs dimensions than non-singleton subscripts" My .png's are numbered sequentially (Heart 001.png, Heart 002.png,...) and my exact code is as follows:
I = zeros(240,320,253,'uint8');
for ii = 1:253
I(:,:,ii) = imread(sprintf('Heart %s.png'),num2str(ii,'%03i')));
end
Any help would be greatly appreciated!
Upvotes: 1
Views: 135
Reputation: 59
I found the solution to be downloading imshow3D.m from http://www.mathworks.com/matlabcentral/fileexchange/41334-imshow3d--3d-imshow- , and then implementing the following code:
clear;
clc;
I = zeros(240,320,253,'uint8');
for k = 1:253
PNGFileName = strcat('Heart ',32, num2str(k), '.png');
imageData = imread(sprintf(PNGFileName));
Heart = imageData(:,:,1);
I(:,:,k) = Heart;
end
imshow3D(I)
Upvotes: 0
Reputation: 5664
Your image reading code looks fine, but the way you construct the file names is wrong. You are passing the result of num2str
to imread
as it's image format argument, but you intended to pass it to sprintf
. How about you try imread(sprintf('Heart %03d.png', ii));
?
Upvotes: 1