is it possible to display the size of an image in MB or KB on matlab?????? if yes how??

10 visualizaciones (últimos 30 días)
plezzz hel asap!!

Respuesta aceptada

Raghava S N
Raghava S N el 3 de Oct. de 2024
Editada: Raghava S N el 3 de Oct. de 2024
Hi Pradeep,
Yes, it is possible to display the size of an image in MB or KB in MATLAB. You can achieve this by calculating its size based on the number of bytes it occupies in memory.
The image size can be calculated using the “imfinfo” function. The “FileSize” output argument of the “imfinfo” function returns the size of the file in bytes. More information about extracting metrics about a graphics file using the “imfinfo” function can be found in this link - https://www.mathworks.com/help/matlab/ref/imfinfo.html#:~:text=character%20vector-,FileSize,-Size%20of%20the.
Here is some sample code to find the size of a graphics file in MATLAB –
imageFilePath = 'path_to_your_image.jpg'; % Replace with your image file path
% Get the size of the image in bytes
info = imfinfo(imageFilePath);
imageSizeInBytes = info.FileSize;
% Convert bytes to KB and MB
imageSizeInKB = imageSizeInBytes / 1024;
imageSizeInMB = imageSizeInKB / 1024;
Hope this helps!
  4 comentarios
DGM
DGM el 3 de Oct. de 2024
Editada: DGM el 3 de Oct. de 2024
OP never clarified what they were actually asking for (other than it should be asap). Decoding the image may be relevant.
% a filename
fname = 'llama.jpg';
% size of file on disk (in kB)
Nfile = imfinfo(fname).FileSize/1E3
Nfile = 135.4700
% size of image in memory (in MB)
inpict = imread(fname);
Nmem = whos('inpict').bytes/1E6
Nmem = 3.4532
Alternatively, attached is a little convenience tool I use
% MIMT memsize() just dumps to console if no output is specified
memsize(inpict,'kB')
3453.192 kB
memsize(inpict,'MB')
3.453 MB
memsize(inpict,'MiB')
3.293 MiB
% but it can produce numeric output as well
Nmem = memsize(inpict,'MB')
Nmem = 3.4532
We can only hope we're not too late to save Pradeep.
Pradeep Gowda
Pradeep Gowda el 5 de Oct. de 2024
Well Well, I finally got my answer after 9 years.
Thanks a lot folks.
This was for my college project😅. I figured it out after posting the question here.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by