1
votes

My code is to getting images from file and and converting images to vector form.

directory = 'C:\Users\Guest\Desktop\FaceRecog\TrainingSet\';
images = dir(strcat(directory,'*.bmp'));
lengthOfFile = length(images);
[m,n] = size(imread(strcat(directory,images(1).name)));
vectorDim = m*n; 
Subjects = zeros(vectorDim,lengthOfFile);

for i=1:lengthOfFile
   imagePath = strcat(directory,images(i).name);
   Temp = reshape(imread(imagePath),[],1);
   Subjects(:,i)=Temp;
end

DblInxSubj = im2double(Subjects); 

Matlab Variables area shows "DblInxSubj" Matrix 77760*40 in size and double type logically correct(and respect to my calculations,too) but when i print a part of this matrix DblInxSubj(1,:) MATLAB printed numbers in a range 0-255 not btw in 0-1.

Finally,im2Double() is not working to convert larger dimensions array ?

for i=1:lengthOfFile
  imagePath = strcat(directory,images(i).name);
  Temp = reshape(imread(imagePath),[],1);
   Subjects(:,i)=Temp;
end

When i changed the statement Subjects(:,i)=Temp; as Subjects(:,i)=im2Double(Temp); i get correct matrix's indexes values in a range 0-1.I don't understand where the difference exactly?

1

1 Answers

4
votes

The difference between double() and im2double() is that double() converts the number into type double, so

double(uint8(8))
> 8

but im2double() converts from typical integer image range (0-255) to typical double image range (0-1). Thus

im2double(uint8(8))
> 0.0314

But careful!! If the image is already a double, then it returns the same value, as converting a double image to double is doing nothing to it.

im2double(8)
> 8