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일

0 개 추천

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

Image Analyst
Image Analyst 2015년 2월 15일
I prefer "axis on" rather than grid on because it doesn't put up anything over the image but just puts tick marks on the outer edges of the image. But I much prefer using a listbox to display the images rather than forcing the user to browse for one. Why not just list all the image names all the time and let the user click on one in a listbox to display it automatically? It's a very much nicer experience for the user. See MAGIC for a nice framework for beginners.
thanks it worked , but I want the user to put the length and width then the grid split based on some equations
I wrote this code which is not working above image
it works only in empty axis
so please help
prompt={'plese insert the value of length(cm)= '}; title='Set Grid'; answer=inputdlg(prompt,title); lengthMod= str2double(answer);
prompt={'plese insert the value of width (cm)= '};
title='Set Grid';
answer=inputdlg(prompt,title);
widthMod= str2double(answer);
% the cell width is constant
CellWidht=50;
% cal the number of rows
NumRows=widthMod/CellWidht;
% cal the number of coul
NumCol=lengthMod/CellWidht;
% cal the number of cell
NumCell=NumRows*NumCol;
x = linspace(1,10,sqrt(NumCell)+1); y = linspace(1,10,sqrt(NumCell)+1);
% Horizontal grid for k = 1:length(y) line([x(1) x(end)], [y(k) y(k)])
end
% Vertical grid for k = 1:length(y) line([x(k) x(k)], [y(1) y(end)]) end
Image Analyst
Image Analyst 2015년 2월 16일
No, don't do that. Simply specify the limits of the x and y axes with the 'xdata' and 'ydata' input options of imshow(). Look it up in the help.
shaimaa almadani
shaimaa almadani 2015년 2월 16일
sorry i didn't get it example please
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일

0 개 추천

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

shaimaa almadani
shaimaa almadani 2015년 2월 17일
thank you thank you thank you it works
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

댓글을 달려면 로그인하십시오.

태그

질문:

2015년 2월 14일

댓글:

2015년 2월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by