user3102085
user3102085

Reputation: 499

How to save image while keeping dimensions and pixels same?

I have to save the image. But when I try and keep the dimensions same, pixel values change. Is there any way to keep both intact.

C=imread('download.jpg');   



 C=rgb2gray(C);

%convert to DCT
 [r1 c1]=size(C);
  CDCT=floor(dct2(C)); 
  dct=floor(dct2(C));
  [r c]= size(dCipherText);
  bye=c; %lenght of message bits
  for i=r1:r1

for j=c1:-1:c1-28


 .....%some operation on CDCT

  end

end 
imshow(idct2(CDCT),[0 255])
i=idct2(CDCT);

 set(gcf,'PaperUnits','inches','PaperPosition',[0 0 c1 r1])
print -djpeg fa.jpg -r1
 end

Upvotes: 0

Views: 185

Answers (1)

Sanjay Manohar
Sanjay Manohar

Reputation: 7026

Don't use print to save the picture. Use:

imwrite(i,'downdload_dct.jpg')

print will use the paper dimensions etc defined on your figure, rather than the image data itself. imwrite uses the data in i. You don't need imshow if you just want to re-save the image.

-- Update - sorry I see now that when you mean 'scaling', you don't mean the scaling of the picture but of the pixel values, and converting back from scalars to a colour. imshow only "scales" things on the screen, not in your actual data. So you will need to do that manually / numerically. Something like this would work, assuming i is real.

% ensure i ranges from 1 to 255 
i = 1 + 254*(i-min(i(:))*(max(i(:))-min(i(:))) ;
% convert indices to RGB colour values (m x n x 3 array)
i = ind2rgb(i,jet(256));

not tested!

Upvotes: 1

Related Questions