Referencia Matlab, Matlab Quick Referece, Matlab Reference
Ufff, siii otro listado de funciones, de los miles y miles que hay. Este es un pequeño listado de funciones bastante útiles y algunos ejemplos sobre el uso del Matlab y procesamiento de imágenes.Para descargar en formato pdf; https://github.com/freelanceparaguay/matlabExamples/tree/master/MatlabReference
Hay miles de guías, interminable cantidad de materiales, esta la hice en base a mis necesidades durante trabajos de procesamiento digital de imágenes.
1 Configuración de entorno
Sentencia | Ejemplo | |
clc | Borrar comandos en consola. | |
clear all | Limpiar valores en | |
close all | Cerrar ventanas |
2 Entradas y salidas
3 Control del flujo y variables
Sentencia | Ejemplo | |
if ... | ti=2; if ti==2 fprintf('Igual a dos'); else fprintf('No es igual a dos'); end ti=2; vi=0; if (ti==2 fprintf('ti=2 y vi=0 else fprint('no cumple \n'); end | |
Existe | ||
switch .. | valor=input('Mensaje switch valor case 1 disp('Valor case 2 disp('Valor -> 2.'); case 3 disp('Valor otherwise disp('Otros valores .'); end | |
while .. | Ti=0; paso=0,5; tiempoFinal=10; while fprintf('t= %.2f ti=ti+paso; end | |
for ... | for ti=0:tiempoFinal fprintf('t= %.2f \n',ti); end |
4 Funciones y procedimientos
Sentencia | Ejemplo | |
function | Función en archivo .m | function [ salida1 salida2 ] = fprintf('entrada1= %.2f \n entrada2=%.2f \',entrada1, entrada2); salida1=10; salida2=20 end Llamar desde la linea de comandos como [a,b]=ejemplofuncion(1,2); Los parámetros se |
@ | Función en línea dentro de un | %definición de función en línea InterpolacionLinealGrado1 = @ (x0,fx0,x1,fx1,x) %llamado a función en línea valorGrado1=InterpolacionLinealGrado1(1,3,5,99,4); |
5 Matrices y vectores
Sentencia | Ejemplo | |
X=[1:10]; | Definición y acceso a un vector | X=[1:10]; X(indice); |
M(fila, | Definición y acceso a una matriz | M=[1, 2, 3; 4, 5, 6; 7, 8, 9] M(fila, columna); |
size() | Tamaño de una matriz | [filas,columnas]=size(X); |
zeros() | Inicializar con ceros | matriz=zeros(n,n); |
Recorrer y mostrar una | X=[1, 2, 3; 4, 5, 6; 7, 8, 9] [n,m]=size(X); for i=1:1:n for fprintf('%.2f ',X(i,j)); end fprintf('\n'); end | |
cat(1,A,I) | Concatenar matrices | A=[1 2 3;4 5 6] I=[1 2 cat(2,A,I) %concatenar columnas cat(1,A,I) % concatenar filas |
A' | Transpuesta de una matriz | A=[1 2 3;4 A' |
det(A) | Determinante | A=[1 2 3;4 5 6; 7 8 determinante=det(A) |
6 Ploteado de funciones
Sentencia | Ejemplo | |
7 Procesamiento digital de imágenes
Sentencia | ||
Abrir imagen | ||
imshow(Iorig); | Mostrar | Iorig=imread('imagen.jpg'); figure; |
Guardar imagen | Iorig=imread('imagen.jpg'); imwrite(Iorig,'prueba.jpg','jpg') | |
Acceder a la matriz de la imagen. | ||
size(originalImage) | Tamaño de imagen, ancho y alto | Iorig=imread('imagen.jpg'); [rows, |
im2bw(Iorig,nivel | Binarizar imagen. 1= 0=NEGRO. | Iorig=imread('imagen.jpg'); nivel = graythresh(Iorig); %umbral de nivel de IB2=im2bw(Iorig,nivel); figure;imshow(IB2); %mostrar |
strel('disk', 3) | Definición de elementos | SE = strel('disk', 3); %disco SE = SE = strel('line', 3, 0); %línea 3 pixeles, 0 grados % otros: ball, octagon, |
imerode(IB2,SE) | Erosión | SE = strel('disk', 3); IB4 = imerode(IB2,SE); figure;imshow(IB4); |
imdilate(IB2,SE) | Dilatación | SE = strel('disk', 3); IB4 = imdilate(IB2,SE); figure;imshow(IB4); |
imclose(IB5,SE) | Apertura | SE = IB7=imclose(IB5,SE); |
imclose(IB5,SE) | Cerradura | SE = IB7=imclose(IB5,SE); |
Invertir | Iorig=imread('imagen.jpg'); IB1=im2bw(Iorig,nivel); IB2=1-IB1; figure; imshow(IB1); figure; imshow(IB2); | |
bitxor(IB7,IB10) | XOR de | Iorig1=imread('imagen.jpg'); Iorig2=imread('imagen.jpg'); IB1=im2bw(Iorig1,nivel); IB2=im2bw(Iorig2,nivel); IB3=bitxor(IB1,IB2); figure; figure; imshow(IB2); figure; imshow(IB3); |
bitor(IB1,IB2) | OR de imágenes | Iorig1=imread('imagen.jpg'); Iorig2=imread('imagen.jpg'); IB1=im2bw(Iorig1,nivel); IB2=im2bw(Iorig2,nivel); IB8=bitor(IB1,IB2); figure; figure; imshow(IB2); |
rgb2gray(Iorig) | Convertir de RGB a grises | Iorig=imread('imagen.jpg'); IG=rgb2gray(Iorig); |
edge(IG,'prewitt') | Filtro | Iorig=imread('imagen.jpg'); Iedges=edge(IG,'prewitt'); %puede figure;imshow(Iedges) |
rgb2gray(Iorig) | Filtro Laplaciano, | Iorig=imread('imagen.jpg'); Iedges=edge(IG,'log'); %puede definirse el umbral de gris figure;imshow(Iedges) |
edge(IG,'prewitt') | Filtro Prewwit, realce de bordes | Iorig=imread('imagen.jpg'); Iedges=edge(IG,'prewitt'); %puede definirse el figure;imshow(Iedges) |
fspecial('average') | Filtro de la media | IB1 = im2bw(Iorig); f=fspecial('average'); IB2=filter2(f,IB1); |
imfill(IB1,'holes') | Llenado de agujeros | Iorig=imread('imagen.jpg'); IB1 = im2bw(Iorig); IB2 = imfill(IB1,'holes'); imshow(BW4), |
regionprops(IB1,'Area') | Cálculo de | area=regionprops(IB1,'Area') fprintf('Area= %.2i; |
regionprops(IB1,'Perimeter') | Cálculo de | perimetro=regionprops(IB1,'Perimeter') fprintf('Perimetro= %.2f \n', |
regionprops(IB1,'Eccentricity') | Cálculo de | excentricidad=regionprops(IB1,'Eccentricity') fprintf('Excentricidad= %.4f \n', excentricidad.Eccentricity); |
regionprops(IB1,'centroid') | Cálculo de centroide | centroides=regionprops(IB1,'centroid') fprintf('X %.2f; Y %.2f\n', centroides(:,1), centroides(:,2)); |
subplot(2,2,1) | Mostrar matriz de imágenes | subplot(2,2,1);imshow(Iorig); subplot(2,2,2);imshow(IB12); subplot(2,2,3);imshow(Iorig); subplot(2,2,4);imshow(IB2); |
8 Historial de cambios
Fecha | Versión | Descripción | Autor |
03/11/2016 | 0,1 | Creación y redacción del documento | http://otroblogdetecnologias.blogspot.com |
Comentarios
Publicar un comentario