简体   繁体   中英

Matlab Query: Image Processing, Editing the Script

I am quite new to image processing and would like to produce an array that stores 10 images. After which I would like to run a for loop through some code that identifies some properties of the images, specifically the surface area of a biological specimen, which then spits out an array containing 10 areas.

Below is what I have managed to scrap up so far, and this is the ensuing error message:

??? Index exceeds matrix dimensions.

Error in ==> Testing1 at 14
    nova(i).img = imread([myDir B(i).name]);

Below is the code I've been working on so far:

my_Dir = 'AC04/';
ext_img='*.jpg';

B = dir([my_Dir ext_img]);
nfile = max(size(B));

nova = zeros(1,nfile);

for i = 1:nfile
    nova(i).img = imread([myDir B(i).name]);
end

areaarray = zeros(1,nfile);

for k = 1:nfile

[nova(k), threshold] = edge(nova(k), 'sobel');
.
.
.
.%code in this area is irrelevant to the problem I think%
.
.
.
areaarray(k) = bwarea(BWfinal);

end

areaarray

There are few ways you could store an image in a kind of an array structure in Matlab. You could use array of struct s. In that case you could do as you did:

nova(i).img = imread([myDir B(i).name]);

You access first image with nova(1).img , second one with nova(2).img etc.


Other way to do it is to use cell array (similar to arrays but are more flexible in the sense that members could be of the different type):

nova{i} = imread([myDir B(i).name]);

You access first image with nova{1} , second one with nova{2} etc.


[ IMPORTANT ] In both cases you should remove this line from code:

nova = zeros(1,nfile);

I suppose you've tried to pre-allocate memory for images, and since you're beginner I advise you not to be concerned with it. It is an optimization concern to be addressed if you come across some performance issues - and if you don't come across them, take advantage of Matlab's automatic memory (re)allocation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM