Sei sulla pagina 1di 31

Tpicos Integradores (PDI)

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

How Data Is Stored


Save data in 8-digit ASCII format.
Save data in 8-digit ASCII format delimited with
tabs.
Save data in 16-digit ASCII format.
Save data in 16-digit ASCII format delimited with
tabs.
Binary MAT-file form (default).

Comandos: ginput, plot e save


Exemplo:
clear, clc
disp('=========================')
disp('<-- PROGRAMA CONTORNO -->')
disp('========================='), disp(' ')
nome=input('Entre com o nome da imagem (ex:
eight.tif) --> ','s'); disp(' ')
I = imread(nome); imshow(I);
disp('Marque os pontos na imagem e para
finalizar, pressione a tecla "Esc" ...'),
disp(' ')

Comandos: ginput, plot e save


Exemplo (continuao):
hold on, k=0; b=0;
while b~=27 %tecla Esc
k=k+1;
[x(k),y(k),b]=ginput(1);
if b~=27
plot(x(k),y(k),'+r');
end
end
x(k)=x(1); y(k)=y(1);
plot(x,y,'-b'), hold off;

Comandos: ginput, plot e save


Exemplo (continuao):
x(k)=[]; y(k)=[];
pts_xy = 'pts_xy.txt';
save 'pts_xy.txt' x y -ASCII;
disp(['Pontos salvos em ' '"' pts_xy
'"']), disp(' ')
disp('
<-- FIM -->')
disp('=========================')

Comandos: ginput, plot e save


Exerccios:
Sabe-se que o centride de um polgono
calculado pelo valor mdio das coordenadas.
Calcule o centride dos polgonos gerados.
Calcule o permetro do polgono.

Sumrio
Comandos (ginput, plot e save)
Sistema de Janelas no MATLAB

Programas com Menu

Programas com Menu


Estrutura: Menu
main_handle = figure('numbertitle','off','name','HistDoc','menubar','none');
imshow('hist_doc.jpg');
file = uimenu('label','File');
uimenu(file,'label','Open Image','callback','open_im','Accelerator','O');
uimenu(file,'label','Save Image','callback','save_im','Accelerator','S');
uimenu(file,'label','Save as','callback','save_as');
...

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');

Programas com Menu


Estrutura: Toolbar
[icon1,map1] = imread('zoomicon.gif');

icon1 = ind2rgb(icon1,map1);

[icon2,map2] = imread('zoomouticon.gif'); icon2 = ind2rgb(icon2,map2);


[icon3,map3] = imread('panicon.gif');

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)';

'*.jpg', 'JPEG (*.jpg)'; ...


'*.bmp','BMP (*.bmp)'; ...
'*.*',

'All Files (*.*)'}, ...

'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]);
...

imshow(I), set(main_handle,'name',['HistDoc - ' fname_in]);


warning on all
end

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');

Obs.: o exemplo foi feito com PDF, mas


tambm pode ser feito em HTML para
ser visualizado no browser do MATLAB
HELP.

Sobre
about_histdoc.m

Sobre
about_histdoc.m
function about_histdoc
help_string = sprintf(['HistDoc v1.0\n\n' ...

'HistDoc is a tool to process ' ...


'historical document images.\n\n' ...
'Developed by DA SILVA, J.M.M and LINS, R.D.\n' ...
'Copyright %c 2007'],169);
help_box
= 'HistDoc Tool - About';
[A,Amap] = imread('histdoclogo.gif');
msgbox(help_string,help_box,'custom',A,Amap)

Potrebbero piacerti anche