Creating an indexed array of images having the same size

3 Ansichten (letzte 30 Tage)
prajwal dk
prajwal dk am 14 Nov. 2014
Beantwortet: David Young am 14 Nov. 2014
I need to create an indexed array of images wherein the images being loaded on to the array are being read from a directory. I have resized each image after reading from the directory using the function 'resizeimage()' and it is a user defined function which returns a resized image of dimension 100x130. The code I am using now is as shown below
files=dir('C:\Users\Documents\MATLAB\*jpg')
for k = 1:numel(files)
rgb= imread(files(k).name)
arr{:,:,k}=resizeimage(rgb)
end
The error that I am currently experiencing is : Cell contents assignment to a non-cell array object.
Error in tvlogocollection2 (line 4) arr{k,:,:}=resizeimage2(rgb)
Could someone suggest changes in the code for this problem

Antworten (1)

David Young
David Young am 14 Nov. 2014
It looks like arr is already a non-cell array. Assuming you don't need the old value of arr, assign a cell array to it before trying to assign to its elements. Also, you only need one index into the cell array. Like this:
arr = cell(1, numel(files));
for k = 1:numel(files)
rgb = imread(files(k).name);
arr{k} = resizeimage(rgb);
end
Also note that you probably want semicolons after the assignments, and that it's helpful if you format code in your question by putting two spaces at the start of each line.

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by