Why rgb2gray(double(imread('picture.jpg')) gives a matrix of value 1?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Aude Rapet
am 16 Jan. 2017
Kommentiert: Aude Rapet
am 16 Jan. 2017
Hi, I am a beginner in Matlab, I try to read my picture that I cropped with paint and convert it to double, and I obtain:
135x194x3 double with
sans=double(imread('aft2.jpg'));
I want to use it with the function normxcorr2, and I have the error message:
Error using normxcorr2
Expected input number 1, T, to be two-dimensional.
Then, I try to convert it with rgb2gray to eliminate the "x3" :
sans=rgb2gray(double(imread('aft2.jpg')));
but it gives me 135x194 double of 1. (my matrix is only composed of the value 1). I obtain this error message:
The values of TEMPLATE cannot all be the same.
So I tried to change my line :
sans=double(rgb2gray(imread('aft2.jpg')));
and it seems that it is working but I dont understand why and what is the difference if I invert rgb2gray and double.
Thank you for your help Aude
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 16 Jan. 2017
Bearbeitet: Image Analyst
am 16 Jan. 2017
You're trying to do too much at once. Simply read it in - it will most likely be a uint8 - then call rgb2gray:
sans = imread('aft2.jpg');
sans2 = rgb2gray(sans); % Convert uint8 color to uint8 gray scale.
sans3 = double(sans2); % Convert to double in the range 0-255.
If you want it to be in the range 0-1 then define sans3 this way:
% Scale min to 0 and max to 1
sans3 = mat2gray(sans2);
or
% Scale 0 to 0 and max to 1
sans3 = double(sans2) / max(sans2(:));
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!