im2frame, imread, movie...difficult. how could i work it?

조회 수: 3 (최근 30일)
youngju kim
youngju kim 2014년 10월 23일
답변: Image Analyst 2014년 10월 24일
i want to make repetitive movie with 24 images, 00000.tif~00023tif using syntax function.
my code is below:
file_path='D:\연구\X-ray\X-ray grating interferometer\talbot carpet simulation\experiment\부산대학교\without_sample\processed';
cmap=colormap(gray);
for i=1:24
if i<=10
temp=strcat(file_path, '\','0000',num2str(i-1),'.tif');
[temp cmap]=imread([temp cmap]);
F(i-1)=im2frame(temp,cmap);
end
end
for i=1:24
if i>10
temp=strcat(file_path, '\','000',num2str(i-1),'.tif');
[temp cmap]=imread([temp cmap]);
F(i-1)=im2frame(temp,cmap);
end
end
movie=movie(F);
When i work this, i got the error:
Error using horzcat CAT arguments dimensions are not consistent.
Error in Untitled (line 7) [temp cmap]=imread([temp cmap]);
Hmmm... what is wrong?

답변 (2개)

Geoff Hayes
Geoff Hayes 2014년 10월 24일
In the line of code that is being used to read the image, you are concatenating the filename (a string/character array) with a 64x3 double matrix
[temp cmap]=imread([temp cmap]);
This may be the result of a copy and paste error, so you should try the following instead
filename = strcat(file_path, '\','0000',num2str(i-1),'.tif');
[img,imgCmap] = imread(filename);
I've changed some of the variable names to make them either give a better idea of what they represent, and/or so as not to conflict with previously defined variables (like the gray colour map).
Note that there is a problem with the F assignment. Remember that MATLAB indexing starts at 1, so you do not want to subtract one when choosing the index of F to update (especially as i starts at one). The line of code
F(i-1)=im2frame(temp,cmap);
should change to
F(i)=im2frame(img,imgCmap);
You could simplify your code by using sprintf instead of strcat and pad automatically the number in the file name with the appropriate number of zeros. Try replacing your above two loops with the following
for k=1:24
filename = fullfile(file_path,sprintf('%04d.tif',k-1));
[img,imgCmap] = imread(filename);
F(k) = im2frame(img,imgCmap);
end
fullfile to combine the path and name of the file. (I replaced the index i with k since i and j are also used to represent the imaginary number.)

Image Analyst
Image Analyst 2014년 10월 24일
This is probably the most Frequently Asked Question. So see the FAQ http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F for examples of robust and adaptable code that works.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by