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

3 visualizaciones (últimos 30 días)
youngju kim
youngju kim el 23 de Oct. de 2014
Respondida: Image Analyst el 24 de Oct. de 2014
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?

Respuestas (2)

Geoff Hayes
Geoff Hayes el 24 de Oct. de 2014
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 el 24 de Oct. de 2014
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.

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by