Image as background in GUIDE

Hello guys,
I'm trying to place an image as a background while working in GUIDE. I'm working with a schematic and I need to place Buttons and Text Boxes on the schematic at certain spots. How would I go about importing the image into GUIDE? The only thing I found was to have an image show after the GUI is run. I need the image to show while I'm creating the GUI in GUIDE in order to see where I'm placing these buttons. Thanks!

 采纳的回答

Matt Fig
Matt Fig 2012-8-9

0 个投票

Check out GUI_40 here:
This was not made with GUIDE but the same principle applies.

13 个评论

im following your example and I'm at line 19 where it says:
X = load('clown')
I replaced clown with the image I want so it now reads:
X = load('test.tif')
And I get this error message:
??? Error using ==> load Unknown text on line number 1 of ASCII file \\VCN.DS.VOLVO.NET\CLI-HM\HM0381\A025074\My Documents\MATLAB\test.tif "I*".
You need to use IMREAD to load your image and not LOAD. Again, this will show the image in the GUI, which you can already do, but I don't think this will result in the image showing up in guide.
You will have to change things around because clown is a MAT file, not an image file. So just look ahead and see where I use the X and X.map to make the image. It is at this point that you can use the example....
Daniel, do you have any idea how to get the image to show up in guide?
Christian,
What Daniel is trying to tell you is that GUIDE is only a tool for building GUIs. You use the this tool to make a GUI for later use: GUIDE is not itself the GUI you are building. So use GUIDE to build your GUI, then when you run the GUI you will see the image if you have programed things correctly.
I understand that. But I need to see the image in order to place the buttons in the right position. I guess that is where GUI_40 comes in I guess
Yes, that is why I showed you that example. I hope it helps you out! Building a GUI exactly like you want is not always easy plug-and-play. Good luck!
Thanks! Okay so I converted my .tif file to a .mat file in order to use the load function in your code. I replaced 'clown' with the name of the mat file and I get this error message:
"??? Reference to non-existent field 'X'.
Error in ==> Untitled3 at 2 S.IMG = ind2rgb(X.X,X.map); % We want to convert it to RGB."
Isn't X defined in the in the previous line of code? It works when the clown is in there but when I put my .mat file in there it doesn't work
The reason why you are getting that error is that the image stored in the clown MAT-file is an indexed image. So in the mat file are two things, the image and the map. I think a tif is not an indexed image. Here is what I did:
At the command line:
X = load('clown');
IMG = ind2rgb(X.X,X.map);
imwrite(IMG,'mytif','tif'); % Make a tif.
Then in the GUI, is did this only to these lines.
% X = load('clown'); % This is a built-in ML example.
% S.IMG = ind2rgb(X.X,X.map); % We want to convert it to RGB.
S.IMG = imread('mytif','tif'); % Use stored tif file.
And it worked. So you should be able to put the name of your file on that last line.
Sorry for all the questions but I'm a little confused. Can you clarify what you did? I still don't understand the X part in ind2rgb. In the command line I entered. schematic is the name of the .mat file that I converted the original .tif file into:
X = load('schematic');
IMG = ind2rgb(X.X, X.map);
After that second line of code I get this error message again:
??? Reference to non-existent field 'X'.
Also 6th line of code you have above, does that replace the 5th line of code?
What is schematic? Did you see I altered three lines in the GUI so that you could use a tif file directly??
Take a step back, re-read what I wrote and look at it with fresh eyes.
X = load('filename')
(as you can see from the help for LOAD!) puts whatever is in the MAT-File 'filename' into the structure X. The fieldnames of the structure are the names of the variables stored in the MAT_File 'filename'.
So, in the MAT-File named 'clown.mat' there are two variables stored: X and map. If you load clown.mat like this:
ST = load('clown')
Then ST will be a structure with two fieldnames, X and map (ST.X and ST.map).
So if you save your tif as a MAT file named 'schematic.mat' then you try to just blindly use the code I originally had in the GUI it will fail because your file only has one variable, not two !
Just use the code I gave above in the GUI so you can use your image directly. I was only showing you how I changed the clown image into a tif so that it could be used by the GUI without conversion (notice those lines are commented out!).
Thank you sir, I think I had a brain fart there for a second! Got it now
You accepted it. Does this do what you want? Can see the image during design time within GUIDE, or you can only see the image once the program is actually run (like I thought, and why I and Sean and Daniel answered the way we did)?

请先登录,再进行评论。

更多回答(2 个)

Image Analyst
Image Analyst 2012-8-9

3 个投票

I don't believe it's possible to have images displayed during design time in GUIDE. It's not Visual Studio after all - not even close.
  1. Create an axes that covers the whole gui.
  2. Have GUIDE automatically generate a CreateFcn for it
  3. In this CreateFcn, Have something along the lines of:
I = imread('cameraman.tif');
imshow(I,'parent',hObject);

4 个评论

In r2011a the image shows up in the gui, but not in guide. In guide I just get an axis with a large X on it. I think Christian wants to see the image in guide.
Couple questions. 1)I converted my image from jpeg into tif. I then saved it in the MATLAB folder. I created the axes, right clicked on GUIDE a clicked CreateFcn. Went into my code in Editor and put what you told me under the CreatFcn part of the code. When I run it the image doesn't show and I get this error message: ??? Undefined function or method 'imshow' for input arguments of type 'uint8'.
Error in ==> untitled1>axes1_CreateFcn at 82 imshow(I, 'parent', hObject);
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> untitled1 at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)untitled1('axes1_CreateFcn',hObject,eventdata,guidata(hObject))
??? Error using ==> struct2handle Error while evaluating axes CreateFcn
2)Will this code allow me to see my image while I'm editing my GUI in GUIDE? It seems as though the image will only appear after the GUI is run
Daniel, yes that is exactly what I want sir!
The IMSHOW function is part of the Image Processing Toolbox. This error suggests you do not have that toolbox. I am pretty sure this solution does not do what you want even if you had the IPT.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by