I think this should work for all bmp image...
function In=loadCNN(filename)
Img=double(imread(filename));
if size(Img,3)==3
Img=mean(Img,3)/255;
end
In=2*Img-1
end
質問
For a university assignment, we were given a MATLAB/Octave toolbox. This includes the following function which should, in theory, read a BMP file and convert it to a matrix, with all values in [-1,1] where -1 means white and 1 means black.
function In=loadCNN(filename)
Img=double(imread(filename));
if size(Img,3)==3
Img=(Img(:,:,1)+Img(:,:,2)+Img(:,:,3))/3;
end
In=((double(Img)/127.5)-1)*-1;
end
However it does not work correctly, returning a matrix with, for example, 0.99216 for white pixels on this image:
Please help me write a function to do this. It should also work for colored BMPs, where it should be converted to grayscale first.
解決
I think this should work for all bmp image...
function In=loadCNN(filename)
Img=double(imread(filename));
if size(Img,3)==3
Img=mean(Img,3)/255;
end
In=2*Img-1
end