reading multiple images from a folder in Matlab
显示 更早的评论
I want to read many images from a folder in the Matlab directory using imread() and then make different operations in every image individually , i wrote this code but it disagrees about (+k+):
num_file=1;
file = dir('image.orig');
num_file = numel(file);
NF=num_file;
Y=1;Z=1;
images = cell(1,NF,T);
T=cell(Y,Z,3);
for k = 1:NF
images{1,k}(Y,Z,3) = imread('C:Work\image.orig\'+k-1+'.JPEG');
end
also, i want to save the matrix of each image in a cell array and i don't if what i wrote is right or not and i cannot have a permission to read from the folder, i checked the folder and found that it is read only, what do you think?
Thank you in advance
采纳的回答
更多回答(4 个)
Image Analyst
2011-11-8
0 个投票
It's always worth throwing in a plug for the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
yasmine
2011-12-8
6 个评论
Walter Roberson
2011-12-8
That is an unrelated matter and should have been posted to a distinct Question.
Count the number of dimensions you have provided in mat2cell: ones-this, ones-that, and 3. So each cell stored will contain a 3D array whose final dimension is 3.
When you go through the de-referencing and cell2mat, you would be coming out with a 3D array. And you try to store that full 3D array in to a single element of the numeric array A -- an array that you initialized to just contain size(C) . One has to wonder what you think you are doing?
Remember too: the result of mat2cell applied to numeric data is going to be a cell array each entry of which contains numeric data. De-referencing that cell array using {} is going to give you a numeric array. You then try to apply cell2mat() to that numeric array even though it is not a cell by that point.
cell2mat is for converting a _group_ of cell entries back in to a single array, and is not called for at all in accessing the contents of a single cell entry.
yasmine
2011-12-8
yasmine
2011-12-9
Walter Roberson
2011-12-9
There is no way to make a nested numeric array. The closest MATLAB equivalent is the cell array whose elements are numeric arrays, and you have already created that (it is your "C")
yasmine
2011-12-9
Walter Roberson
2011-12-9
I think this should definitely have gone in its own thread ;-)
You are trying to apply imhist() to a (subsection of) a truecolor image (which is thus a 3D matrix). imhist() is only for grayscale images. You should convert your whole image to grayscale before you break it up in to blocks; or you should convert each block to grayscale and imhist that as you go; or you should imhist() each of the three color planes separately.
Shaveta Arora
2016-4-9
0 个投票
If I have .tiff images and .tif images that I want to read, how they can be read ? I know how to read one type of images but how to read two types of images.
4 个评论
Walter Roberson
2016-4-9
dstats1 = dir('*.tiff');
dstats2 = dir('*.tif');
dstats = [dstats1; dstats2];
filenames = {dstats.name};
for K = 1 : length(filenames)
load_images{K} = imread(filenames{K});
end
Emily Leung
2021-6-18
Hi this doesnt work for me, filenames comes up empty. Do you know what might be the issue?
Walter Roberson
2021-6-18
@Emily LeungIn the code I posted here, the filenames would come up empty if you do not have any .tif or .tiff files in the current directory.
In some cases, depending upon operating system configuration, files ending with extension .TIF or .TIFF might not be treated as if they ended in .tif or .tiff -- sometimes files are case sensitive.
The code I posted is not designed to look for files in a different directory; the changes to look in a different directory are not difficult though.
Emily Leung
2021-6-18
@Walter Roberson i solved the issue, thank you very much this approach saved me many an if loop!
Kumar Vaibhav
2016-8-1
编辑:Walter Roberson
2016-8-1
I=imread(sprintf('C:/Users/kumar.vaibhav/Documents/MATLAB/Visually Similar Images/%d.jpeg',i));
1 个评论
Walter Roberson
2016-8-1
Kumar, is there a question associated with that?
类别
在 帮助中心 和 File Exchange 中查找有关 Neighborhood and Block Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!