Filter löschen
Filter löschen

Image arrays and converting matrix to line

1 Ansicht (letzte 30 Tage)
Recap
Recap am 13 Mär. 2016
Bearbeitet: Recap am 14 Mär. 2016
Can someone explain what each line is doing in this code and how it's doing it, if possible?
I commented the best I could to get a general understanding of what's going on. But I don't understand it in detail. Like what the main lines of code are actually doing.
for i=1:10
FName=sprintf('%d.bmp',i);
image1=imread([FFolder1, FName]);
% Creating a 3D image for every number and implementing it in every loop
im1(:,:,i)=image1; % "A"
end
for i=1:M
FName=sprintf('%d.bmp',i+10);
image1t=imread([FFolder1, FName]);
im1t(:,:,i)=image1t; % "A"
end
for i=1:10 % Training images
im(:,:,i)=im1(:,:,i);
end
for i=1:20
imt(:,:,i)=im1t(:,:,i);
end
% The transition of values (0 1) to the range (0: 255)
for i=1:10*10 % Training images
imd(:,:,i)=(im2double(im(:,:,i)));
end
for i=1:10*20
imdt(:,:,i)=(im2double(imt(:,:,i)));
end
for s=1:10*10
for i=1:40
for j=1:120
Xv(s,(i-1)*120+j)=imd(j,i,s);
end
end
end
sizeXv=size(Xv);

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 14 Mär. 2016
There is a lot there which is inefficient.
The first two loops do not create a 3D array for each number. They read images as "slices" in a 3D array.
The code
for i=1:N % Training images
im(:,:,i)=im1(:,:,i);
end
can be coded much more compactly as
im = im1;
since im1 is exactly N panes long anyhow. Likewise the training and test can be done by simple copying of entire arrays.
For
for i=1:10*N % Training images
imd(:,:,i)=(im2double(im(:,:,i)));
end
you might prefer this code, but it is not the most efficient. More efficient would be to work on the entire array at one time,
if isa(im, 'uint8') %bmp can be logical or 8 bit or 24 but not 16 bit
imd = double(im) ./ (2^8-1);
else
imd = double(im);
end
and if you were sure ahead of time which data class it was going to be, you could optimize that. I suspect you are working with uint8 images.
The last bit could be rewritten as
Xv = reshape(imd, size(imd,1)*size(imd,2), size(imd,3)) .';

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by