Saved image is different when read in matlab -
i created matrix using calculation.i saved in bmp format.but when reading in matlab,the content of changes totally.only value 0 correct.all other pixels having values 255.why this.how solve this?? showing image correctly when imsec command used
i=1:length(pixel_matrix) pixel=char(pixel_matrix(i)); r=7; pixel_value=0; j=1:4 s=r-1; if(pixel(j)=='a') temp_bin=0; elseif(pixel(j)=='b') temp_bin=(2^r)+(2^s); elseif(pixel(j)=='c') temp_bin=(2^s); elseif(pixel(j)=='d') temp_bin=(2^r); end pixel_value=pixel_value+temp_bin; r=r-2; end pixel_row(i)=pixel_value; end i=1; j=1; m=1:length(pixel_row) pixel_value(i,j)=pixel_row(m); j=j+1; if(j==65) i=i+1; j=1; end end i=1:64 j=1:64 picture(i,j)=uint8(pixel_value(i,j)); end end imwrite(picture,'c:\users\xxx\desktop\pic.bmp'); aaaa=imread('c:\users\xxx\desktop\pic.bmp');
the problem filling picture
uint8
values, when not specified otherwise, images in matlab doubles between 0 , 1. try using map
option imwrite
or norm values of pixel_value(i,j)
fit them between 0 , 1 this:
%... i=1:64 j=1:64 picture(i,j)=pixel_value(i,j)/255; %<- norm things here... end end
Comments
Post a Comment