problem in image resizing

4 ビュー (過去 30 日間)
Shashank Rao
Shashank Rao 2013 年 5 月 18 日
i used following codes for resize an image to user deffined memory size. but while saving that image using imwrite the size of saved image is not exact given size. size is less than given size. for 100KB it gives 75.5KB. but when i checked using whos functio the bytes are exact to required size... plz help me any one.. ----------------------------------------------------------------------- %Program to rescale an image%
close all;
X=imread('cameraman.tif'); %--------------------------- -load an image%
disp('enter the required memory size'); %----------------instruction%
disp('if memory size is 100KB, then just enter 100');%---instruction%
K=input('output image size=');%--------------------------resultant image size%
s = K*(1024); %------------------------------------------convert entred integer into memory size%
M = sqrt(s);%--------------------------------------------calculate the required no. of row and coloumn%
Y = imresize(X, [M,M],'bilinear'); %---------------------rescaling using bilinear transform%
figure()
imshow(X);
title('original image');
figure(); %----------------------------------------------display the images%
imshow(Y);
title('rescaled image');
imwrite(Y,'hny.gif'); % ---------------------------------save image into computer%
whos Y; %----------------------------------------------calculates the image size in bytes, and no. of rows and coloumns%

採用された回答

Jurgen
Jurgen 2013 年 5 月 18 日
Have you tried .bmp? I think that does not use compression. It should be slightly greater than 100KB due to the header.
  2 件のコメント
Shashank Rao
Shashank Rao 2013 年 5 月 18 日
sir i have tried that... but i was saving as 4bit image insted of 8bit... so i thinnk .bmp image was about 48KB
Jurgen
Jurgen 2013 年 5 月 18 日
I just tested your code with 100KB .bmp, file is 101KB in windows explorer. I dont know what u mean with saving it as 4bit image.

サインインしてコメントする。

その他の回答 (2 件)

Jan
Jan 2013 年 5 月 18 日
Did you see how ugly your code looks like? It would be attract more readers if you use the standard formatting methods of this forum.
You save the image as GIF. Then it is expected and wanted, that the size differs from the data size:
  1. The image file needs additional information like a header about the type of the file format and meta data, a color map etc.
  2. The data itself are compressed to save disk space.
  2 件のコメント
Shashank Rao
Shashank Rao 2013 年 5 月 18 日
sorry.... i am a beginer in this field. i tried with many other farmat also like jpg, png,tig etc. there also i am facing same problem
Image Analyst
Image Analyst 2013 年 5 月 18 日
Jan is correct. You are calling this a "problem" and that is not correct. It is NOT a problem. It is the expected behavior and you should appreciate it, not try to avoid it. I'd recommend you use PNG format - it's fast becoming the new standard for simple images. It uses lossless compression and every software package now supports it. I have heard that even though the CPU compresses it, it's faster to do that than to not compress it because the disk I/O is slower than the CPU compression time. So, bottom line, if I were you, I'd just save with PNG format and mark Jan's answer as "Accepted."

サインインしてコメントする。


fewf
fewf 2013 年 7 月 12 日
編集済み: fewf 2013 年 7 月 12 日
here are some image resizer codes in vb.net for you. it is much simpler. besides for the image formats i high recommend tiff. it is a less lossy compression image formats.

カテゴリ

Help Center および File ExchangeImport, Export, and Conversion についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by