I am using Octave 3.6.4 to process an image and store it afterwards. The image I read is grayscale, and after calculations the matrix should be of the same type. However, if I open the stored image, there are no gray pixels. There are only black and white ones and the gray ones got lost. They are essentially all white.
Here is the processing code:
function aufgabe13()
[img, map, alpha] = imread("Buche.png");
[imax, jmax] = size(img);
a = 0.7;
M = 255 * ones(imax,jmax + round(imax * a));
for i = 1:imax
begin = round((imax-i)*a);
M(i,begin +1 : begin + jmax) = img(i,:);
end
imwrite(M, 'BucheScherung.png', 'png');
end
So what am I doing wrong?
The reason why is because
M
is adouble
matrix so the values are expected to be between[0,1]
when representing an image. Because your values in your image are between[0,255]
when read in (typeuint8
), a lot of the values are white because they're beyond the value of 1. What you should do is convert the image so that it is double precision and normalized between[0,1]
, then proceed as normal. This can be done with theim2double
function.In other words, do this: