display image informations via gui using imfinfo

1 view (last 30 days)
hello , i am tried to show (display) the informations of images wich i load them and applicate a defferents tests of denoising, i used a push-button and text-edit , button to display informations, so, for exemple i need to show the width:
function push-button_Callback(hObject, eventdata, handles) global image
info=imfinfo('image');
the-width=info.Width;
set(handles.text-edit,'string',the-width);
nothing appears and i get this errors
??? Error using ==> imfinfo at 96 Unable to open file "image" for reading.
Error in ==> app>info_Callback at 1741 info=imfinfo('image');
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> app at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)app('info_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

Accepted Answer

Benjamin Avants
Benjamin Avants on 16 May 2014
First, I would suggest not using a global variable to store your image or images. It would be better to save the image data to the handles data structure.
% load image
% process image
% display image
handles.image = image;
guidata(hObject,handles);
This way, any callback that needs the image data can retrieve it from the handles structure and you don't need to use the global variable. You can do this with any shared data or variable in a GUI created with guide.
The problem in your code is that imfinfo() requires a filename as a parameter, not a loaded image. If all you want is the width of the image in pixels, you can get it from the size of the image data.
width = size(image,1);
height = size(image,2);
-OR-
width = size(handles.image,1);
height = size(handles.image,2); % If you've stored the image in the handles data structure
If you need other info about the file, you can either compute it yourself or get it from the file when you load the image and store it in the handles structure.
image = imread('image.bmp');
handles.info = imfinfo('image.bmp');
guidata(hObject,handles);
If the information about the image that you're looking for changes after you've processed the image, you'll either need to save the new image as a file and then use imfinfo or, as mentioned, compute the new information yourself.

More Answers (1)

matlab22
matlab22 on 16 May 2014
thanks for the answer,
width = size(image,1); height = size(image,2);
works perfectly, but the probleme that i must load differnet image formats bmp,jpg,gif,png how can i give imfinfo the fmt each time i load an image:
handles.info = imfinfo('image.bmp'); % .bmp or jpg or .......
and for real i wanna display more than the width but also filename ,size ,width ,higth.

Categories

Find more on Images in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!