i'm trying to read a RGB BMP format image and a JPG format image. but it appears that both have same size(bytes) on my work space . is it possible to read the image with their actual disk space?

 Réponse acceptée

You'd have to use fread(), instead of imread(), to read in the image data byte-for-byte. Of course it does no decompressing that way - it's just pure raw bytes and would look like garbage if you went to display it. Why do you want to do that anyway?

12 commentaires

okay thank you.:) i'm working on image compression(jpeg algorithm DCT). I need to display its actual disk space on my GUI and the disk space of my compressed image. so that it would be convincing that a huge quantity of space is reduced . this is the actual problem i'm facing, please give any suggestion for implementing this.
That's different than what you asked, which is that you wanted to read the image file bytes into your workspace and have them be the actual size in the workspace as they are on disk. To simply get the filesize on disk, you can use imfinfo() or dir() like John showed.
oh okay! thanx a lot! :D
okay now one more thing . I got a way to display size of input image . does the same work for the compressed image ?
What size? Size of what ? The number of rows and columns will be the same. The number of bytes using fread() will not be the same. The number of bytes, and number of rows and columns using imread() will all be the same.
yeah, i understood that part,i'm working on jpeg compression algorithm. now as john said i can use dir() to display the actual size of the image and after running my algorithm ill get a compressed image depenging on the quality given my user. now i need to display the size of this compressed image. that is what i asked.
You did not specify how you want it displayed so now I guess I'll have to list a few of the ways that you can display the size.
  1. You can use fprintf() to display it in the command window.
  2. Or you can just put the size on its own line in your code to display it in the command window.
  3. If you have a static text label on a GUI, you can use set() to send a string with the size in it to your static text label.
  4. You can display the text in a string over an image or a plot/chart/graph with text().
  5. You can make up a string and then display it with msgbox() or helpdlg().
There are other ways too. I didn't want to make up demos for all 5 of those because 4 of them you won't even use. Explain exactly what "display" means to you.
sorry! i wanna display it on my GUI. i mean the size of the compressed image after running the code.
Then it's #3:
message = sprintf('The size is %d bytes', numberOfBytes);
set(handles.text1, 'String', message);
thankxx a lot :D and suppose i have number 5.70787644444 how do i consider just first 2 decimal places in that
That's a completely different question, and one that you asked and accepted an answer to in a completely different discussion, so I won't answer it here.
oh okay . thnkxx for all the information that you gave me. i'm almost done with my project. thnkxx once again :D

Connectez-vous pour commenter.

Plus de réponses (1)

So all you want to know is how much disk space was taken up by the image, NOT to read it in with the file still in compressed format?
Just use dir. Look at the struct form that dir returns. One of the fields is bytes, i.e., the number of bytes taken up by the file on disk, as it is currently stored.
For example, in my current directory, I have a jpg file stored.
d = dir('untitled.jpg')
d =
name: 'untitled.jpg'
date: '05-Feb-2015 10:59:57'
bytes: 20014
isdir: 0
datenum: 7.36e+05
If your goal is to also know the space required to store the image in an uncompressed form, then you need only to know the size of the image.

2 commentaires

okay thank you. i have doubt now, is the space required to store the uncompressed image and its disk space are different?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by