Creating an indexed array of images having the same size

조회 수: 1 (최근 30일)
prajwal dk
prajwal dk 2014년 11월 14일
답변: David Young 2014년 11월 14일
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

답변 (1개)

David Young
David Young 2014년 11월 14일
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.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by