using image in gui

2 ビュー (過去 30 日間)
shaimaa almadani
shaimaa almadani 2015 年 2 月 14 日
コメント済み: shaimaa almadani 2015 年 2 月 18 日
hello I'm new to matlab I hope you can help me
I'm making program in gui that can import image
so i wrote this code
[filename, pathname] = uigetfile('*.png');
layout=imread(filename);
imshow(layout);
and when i press button I want to open the image in new window with a grid on it
how can i do this
your help will be appreciated

回答 (2 件)

Geoff Hayes
Geoff Hayes 2015 年 2 月 15 日
Shaimaa - presumably your code (from above) will be placed in the callback function to a pushbutton on your GUI that has been created with GUIDE. If your pushbutton is named (or its Tag property is set to) pushbutton1, then the callback would look like
function pushbutton1_Callback(hObject, eventdata, handles)
% let the user choose the file
[filename, pathname] = uigetfile('*.png');
Now once the file has been picked, you want to read it (as you have shown) with imread. But you will have to include the path to the file and not just the file name. Use the function fullfile to "build" the path with file name for you
layout=imread(fullfile(pathname,filename));
imshow(layout);
The above should display the image in a new figure. If you want the grid lines to display, then use grid as
grid on;
These four lines of code will make up the body of your callback. Try the above and see what happens!
  6 件のコメント
Geoff Hayes
Geoff Hayes 2015 年 2 月 16 日
See the Name-Value Pair Arguments section of imshow.
shaimaa almadani
shaimaa almadani 2015 年 2 月 17 日
and how can the user choose the value of length and width

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


Image Analyst
Image Analyst 2015 年 2 月 17 日
If you want your tick marks to read from 0 to 4 cm horizontally and 0 to 3, then do this:
rgbImage = imread('onion.png');
imshow(rgbImage, 'Xdata',[0 4], 'Ydata', [0, 3]);
axis on;
Otherwise the tick marks will read out in units of pixels.
  3 件のコメント
Image Analyst
Image Analyst 2015 年 2 月 17 日
編集済み: Image Analyst 2015 年 2 月 17 日
You're welcome. Note though that this just affects the display. If you make any measurements with regionprops, such as area, the values are still in pixels. Can you mark the answer as "Accepted" then? Thanks in advance.
shaimaa almadani
shaimaa almadani 2015 年 2 月 18 日
what about if i want to take the length and width from the user

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

カテゴリ

Help Center および File ExchangeRead, Write, and Modify Image についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by