how to load a folder of images in variables using for loop and arrays ?
Mostrar comentarios más antiguos
Im working on dip.I have a folder of binary images and i want to create variable to each image using arrays and for loop concept
1 comentario
Image Analyst
el 11 de Feb. de 2015
Respuesta aceptada
Más respuestas (2)
Sevil Ahmed
el 11 de Feb. de 2015
Hi, in similar cases I use strings... Here is the code, which I prepare for you. I hope it will help!
%Example code for reading 10 *.bmp files named as it follows: 1.bmp, 2.bmp.......... 10.bmp
%You should be (or go) into the correct directory which contains the files
for PicNum=1:1:10;
fullFileName=strcat(num2str(PicNum),'.bmp');
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
end
You should only rename your *.bmp files (if you are allowed to do it).
Good luck!
Use this code if you have a known sequence of filenames. It saves all of the image data in a cell array too:
myBase = 'image'; % selects the base filename: 'image1.bmp','image2.bmp', etc.
myFolder = 'e:\\invertedimages';
for PicNum = 10:-1:1;
fullFileName = fullfile(myFolder,sprintf('%s%.0f.bmp',myBase,PicNum));
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray{PicNum} = imread(fullFileName);
imshow(imageArray{PicNum}); % Display image.
end
3 comentarios
neha viswanath
el 11 de Feb. de 2015
Stephen23
el 11 de Feb. de 2015
The cell array imageArray stores all image data from every image that is loaded by this function. Each image is located in one cell of the cell array: imageArray{k}. The data is in a numeric array: the exact dimensions of each numeric array depend on the size of the image and its color-encoding.
"I need to create logical type variable of 50*50 ..." : this seems to be a different topic to your original question, which all of the answers given here have tried to resolve for you. If you wish to discuss a new topic, you should ask this as a new question, or even better do a little bit of your own research first:
Image Analyst
el 11 de Feb. de 2015
neha, are you using imageArray{1} like you said rather than imageArray{k} or imageArray{PicNum} like Stephen told you here and I told you in your duplicate question???
And your second question is totally different, and not even answerable because it does not say how you'd like to convert the color or gray level image into a logical image (like by thresholding or whatever).
Categorías
Más información sobre Convert Image Type en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!