Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Suporte a MATLAB
Prof. Joo Marcelo M. da Silva
2015.2
Sumrio
Comandos (ginput, plot e save)
Sistema de Janelas no MATLAB
Sumrio
Comandos (ginput, plot e save)
Sistema de Janelas no MATLAB
Objetivo
Deseja-se um programa que:
adquira pontos da tela pelo mouse;
mostre o local onde os pontos foram
adquiridos;
salve estes pontos.
Resultado
Resultado esperado.
Comando: ginput
ginput Graphical input from mouse.
[x,y] = ginput(n) enables you to select n
points from the current axes and returns the xand y-coordinates in the column vectors x and
y, respectively. Press the Return key to
terminate the input before entering n points.
Comando: ginput
ginput Graphical input from mouse.
[x,y] = ginput gathers an unlimited
number of points until you press the Return
key.
[x,y,button] = ginput(...) returns the
x-coordinates, the y-coordinates, and the
button or key designation. button is a vector
of integers indicating which mouse buttons you
pressed (1 for left, 2 for middle, 3 for right), or
ASCII numbers indicating which keys on the
keyboard you pressed.
Comando: ginput
Exemplo:
I = imread('eight.tif');
imshow(I);
[x,y] = ginput;
Comando: plot
plot 2-D line plot.
plot(Y) plots the columns of Y versus their
index.
plot(X1,Y1,...) plots all lines defined by
Xn versus Yn pairs.
plot(X1,Y1,LineSpec,...) plots all lines
defined by the Xn,Yn,LineSpec triples, where
LineSpec is a line specification that
determines line type, marker symbol, and color
of the plotted lines.
Comando: plot
LineSpec Line specification string syntax.
Specifier Line Style
Solid line (default)
-Dashed line
:
Dotted line
-.
Dash-dot line
Specifier Color
r
Red
g
Green
b
Blue
c
Cyan
m
Magenta
y
Yellow
k
Black
w
White
Specifier
+
o
*
.
x
'square' or s
'diamond' or d
^
v
>
<
'pentagram' or p
'hexagram' or h
Marker Type
Plus sign
Circle
Asterisk
Point
Cross
Square
Diamond
Upward-pointing triangle
Downward-pointing triangle
Right-pointing triangle
Left-pointing triangle
Five-pointed star (pentagram)
Six-pointed star (hexagram)
Comando: plot
Exemplo:
I = imread('eight.tif');
imshow(I);
[x,y] = ginput;
%exibio dos contornos
x(end+1)=x(1);
y(end+1)=y(1);
hold on
plot(x,y,'-b');
plot(x,y,'xr');
Comando: save
save filename stores all variables in the
current workspace in the file filename.
save filename content options
stores only those variables specified by
content in file filename, also applying
the specified options.
Example:
save 'pts_xy.txt' x y -ASCII;
save('pts_xy.txt','x','y','-ASCII');
Comando: save
Format Options:
MAT-file format Options
-ascii
-ascii -tabs
-ascii -double
-ascii -double -tabs
-mat
Sumrio
Comandos (ginput, plot e save)
Sistema de Janelas no MATLAB
edit = uimenu('label','Edit');
uimenu(edit,'label','Undo/Redo','callback','undo_redo_im','Accelerator','Z');
...
transformation = uimenu('label','Transformation');
uimenu(transformation,'label','RGB to Gray','callback','rgb_gray');
...
help_histdoc = uimenu('label','Help');
uimenu(help_histdoc,'label','Help','callback','help_histdoc');
uimenu(help_histdoc,'label','About','callback','about_histdoc');
icon1 = ind2rgb(icon1,map1);
icon3 = ind2rgb(icon3,map3);
[icon4,map4] = imread('openicon.gif');
icon4 = ind2rgb(icon4,map4);
[icon5,map5] = imread('saveicon.gif');
icon5 = ind2rgb(icon5,map5);
[icon6,map6] = imread('undoicon.gif');
icon6 = ind2rgb(icon6,map6);
TOOLbar = uitoolbar(main_handle);
uipushtool(TOOLbar,'CData',icon4,'TooltipString','Open','ClickedCallback','open_im');
uipushtool(TOOLbar,'CData',icon5,'TooltipString','Save','ClickedCallback','save_im');
...
clear icon1 icon2 icon3 icon4 icon5 icon6 map1 map2 map3 map4 map5 map6;
Abrir Imagens
open_im.m
Abrir Imagens
open_im.m
function open_im
[fname,pname] = uigetfile( ...
{'*.jpg;*.bmp','IMAGE Files (*.jpg,*.bmp)';
'Select an Image');
if size(fname,2)>1 && size(pname,2)>1
global main_handle
close(main_handle),HistDoc
global main_handle fname_in pname_in
fname_in = fname;
pname_in = pname;
global I I_AUX
I=imread([pname_in,fname_in]);
...
Salvar Imagens
save_as.m
Salvar Imagens
save_as.m
function save_as
global fname_in pname_in I main_handle
if prod(size(I))~=0
[fname, pname, filterindex] = uiputfile( ...
{'*.jpg;*.bmp','IMAGE Files (*.jpg,*.bmp)';
'*.jpg', 'JPEG (*.jpg)'; ...
'*.bmp','BMP (*.bmp)'; ...
'*.*', 'All Files (*.*)'}, ...
'Save as', fname_in);
if size(fname,2)>1 && size(pname,2)>1
imwrite(I,[pname,fname]);
fname_in = fname;
pname_in = pname;
set(main_handle,'name',['HistDoc - ' fname_in]);
end
end
Converte: RGB NC
rgb_gray.m
Converte: RGB NC
rgb_gray.m
function rgb_gray
global I I_AUX
if prod(size(I))~=0
I_AUX = I;
I = rgb2gray(I);
hold on, imshow(I), hold off
end
Ajuda
help_histdoc.m
Ajuda
help_histdoc.m
function help_histdoc
help_string = sprintf(['We are sory, but the HistDoc\n' ...
'tool is under construction' ...
'.']);
help_box
= 'HistDoc Tool - Help';
[A,Amap] = imread('histdoclogo.gif');
msgbox(help_string,help_box,'custom',A,Amap)
open('HistDoc.pdf');
Sobre
about_histdoc.m
Sobre
about_histdoc.m
function about_histdoc
help_string = sprintf(['HistDoc v1.0\n\n' ...