MAGENES - 148.206.53.231

125
UNIVERSIDAD AUTÓNOMA METROPOLITANA - 1 27": CIENCIAS BÁSICAS E INGENIERíA LICENCIATURA EN COM P UTAC I ON PROYECTO TERMINAL: PROCESAMIENTO DIGITAL DE /MAGENES PART1 C I PANTE S : JQSÉ ANTONIO LOPEZ POSADA (86222802) JORGE HIGAREDA ISLAS (86222573) ASESOR: DR. OCTAVIO RAÚL ARZATE SOLTERO DEPTO. MATEMÁTICAS UAM-I México, D.F., Febrero de 1992.

Transcript of MAGENES - 148.206.53.231

Page 1: MAGENES - 148.206.53.231

UNIVERSIDAD AUTÓNOMA METROPOLITANA - 1 27":

CIENCIAS BÁSICAS E INGENIERíA

LICENCIATURA EN COM P UTAC I ON

PROYECTO TERMINAL:

PROCESAMIENTO DIGITAL DE /MAGENES

PART1 C I PANTE S :

JQSÉ ANTONIO LOPEZ POSADA (86222802) JORGE HIGAREDA ISLAS (86222573)

ASESOR:

DR. OCTAVIO RAÚL ARZATE SOLTERO DEPTO. MATEMÁTICAS UAM-I

México, D.F., Febrero de 1992.

Page 2: MAGENES - 148.206.53.231

CONTENlDO

Introducción - Operaciones aritméticas

Suma de Imágenes -

Resta de Imágenes I

hlultiplicación de Imágenes -

Division El gradiente de una Imagen -

La transformación espacial- -

Interpolación de los niveles de gris Transferencia de los pixeles -

Usos de las operaciones puntuales Operaciones puntuales lineales- Operaciones puntuales y los histogramas

Operaciones morfologicas Erosión - Dilatación

Pasa bajos - Pasa alta

Programa fuente Organización -

Principal Grad ¡en te Suma de Imagenes - Resta de Imágenes - MultipliCaCicn de Imágenes - División Mascara Rotación Traslación Reflexión Horizontal -

Reflexi6i; Vetical Contraste Escala de niveles de gris Inversión de tina Imagen Fcinción de distribución - Di iatació ti Erosion - Pasa alta Pasa bajos -

Libreria para el manejo de Imágenes en Disco y Videc; - Definición del conjunto de caracteres utilizados Libreria para menús en Modo Gráfico 13h Selección de Imágenes de Disco Manejo d e ventanas en Modo .Gráfico ?3h

Operaciones geométricas

-

Operaciones puntuales -

Fi Itros

Librerías

Eiibliografia -

3

7

7 1

7

8 8 9

11 ? 3

14 14

16 20 24 25 27 28 30 32 38 40 42 44 47 48 . 50 52 55 61 08 72

76 a5 88 1 05 I o9 120

2

Page 3: MAGENES - 148.206.53.231

El procesamiento digital de imágenes es, la manipulación de imágenes por computadora; este tipo de procesamiento es relativamente reciente y tiene todo un mundo de aplicaciones en la sociedad moderna, se utiliza por ejemplo en la restauración de imágenes deterioradas, en la clasificación de objetos, en el reconocimiento de patrones, etc. Para el procesamiento digital de imágenes se requieren conocimientos de diversas áreas como son: la Óptica, Electrónica, Matemáticas, Fotografía y tecnología en computación.

El procesamiento digital de imágenes es posible solamente si se cuenta con un sistema de computación con dispositivos de entradalsalida, digitalizador de imágenes y un dispositivo de despliegue de buena resolución.

La digitalización de una imagen es el proceso de convertir pequeñas áreas de una imagen (pixeles) a una forma numérica: la imagen es dividida por líneas horizontales y verticales, cada cruce de línea representa un pixel. Cada pixel tiene un cierto brillo que es cuantificable y representado por un entero. De esta manera, una imagen se puede representar por un arreglo rectángular de enteros, donde cada una de sus entradas estará representado por: pixel (renglón, columna, nivel de gris). El nivel de gris representa la brillantez de la imagen.

Imagen Nivel de gris Negro

Blanco

256

128

O

El nivel de gris (O) representa un pixel claro, y el nivel de gris (256) un pixel negro

A la imagen representada en niveles de gris en una arreglo se le pueden hacer operaciones matemáticas como: aritméticas, geométricas, puntuales, morfológicas, las cuales se analizarán en las siguientes páginas.

3

Page 4: MAGENES - 148.206.53.231

OPERACIONES ARITMÉTICAS

Como se mencionó, las imágenes digitalitadas son representadas en arreglos rectángulares cuyas entradas son los niveles de gris de la imagen. las operaciones algebraicas tales como: la adición, resta, división y producto de imágenes se realizan pixel a pixel. Por ejemplo si se tienen dos imágenes A (x,y) y B(x,y) y se desea sumar el pixel en la columna I, renglón 5 de las imágenes obtenemos.

A(15) = Nivel de gris 23 B ( 1 3 = Nivel de gris 56 C(15) = A(IIS) + B ( 1 3 C(1,S) = 79

Si se realiza una operación algebraica con una imagen y una constante o con otra imagen idéntica, el problema puede resolverse mediante una operación puntual lineal.

Matemáticamente las operaciones aritméticas anteriores se expresan como sigue:

Donde A(x,y), B(x,y), C(x,y), representan imágenes.

ADICIÓN DE IMÁGENES

En una escena estacionaria en algún “ruido”, ya sea del ambiente a

la cual, tomar

una imagen es contaminada por 3 fotografía, o en el proceso de

digitalización , el ruido agregado a la imagen puede ser eliminado en parte obteniendo múltiples imágenes de la misma escena y promediándoias.

Si suponemos que se tienen ’M’ imágenes y que de alguna manera podemos separar la imagen ‘y’ con ruido en dos imágenes , una libre de “ruido” y otra que únicamente contenga el “ruido”, entonces cada imagen la escena pt i t - . , { ecprPCsntado de la siguientc ,, ianera:

4

Page 5: MAGENES - 148.206.53.231

Donde S(x,y) es la imagen de interés libre de ruido y, Ni(x,y) es el ruido de cada imagen.

Para la eliminación del ruido, se supone que cada imagen está contaminada

En este problema, se aplica la Adición de imágenes para obtener la imagen con ruido diferente.

ruido promedio.

RESTA DE IMÁGENES

En algunas ocasiones se obtienen imágenes en secuencia de una escena con la intención de detectar si hubo algún cambio en la escena, los cambios pueden ser tan leves que resulta cosa imposible notarlos en las imágenes. Si se restan dos imágenes como io muestra la siguiente ecuación, es posible detectar el o los cambios.

Todos aquéllos puntos (pixeles) en la primera imagen que no sufrieron cambios, aparecen en la misma posición (x,y) en la segunda imagen, al restarlas pixel a pixel se obtiene un nivel de gris (O), y los puntos que si sufrieron cambios aparecen en otra posición (x,y) en la segunda imagen y al restarlas pixel a pixel, se obtiene un nivel de gris diferente de cero. En conclusión, la imagen C(x,y) resultado de la resta contendrá :

Pixeies con nivel de gris (O), donde no hubo movimiento y, Pixeles con nivel de gris (diferente de O), donde hubo movimiento.

PRODUCTO DE IMÁGENES

El producto puede ser utilizado para ocultar {enmascarar) partes de una imagen. Cuando se desea suprimir algunas regiones de una imagen, se marcan con nivel de gris (O) y la parte restante se oculta. El producto de una imagen por una máscara dará el valor de cero a una área específica. Se puede producir entonces, una máscara complementaria en una segunda imagen que borrará las áreas retenidas en la primera imagen. Las dos imágenes enmascaradas se pueden sumar para formar el producto final.

DiViSióN DE IMÁGENES

La división puede ser usado para generar razones (o proporciones) de imágenes, esto es muy útil en análisis espectral.

5

Page 6: MAGENES - 148.206.53.231

GRADIENTE DE UNA IMAGEN

La diferencia de imagen se utiliza también para obtener la magnitud del gradiente de una imagen. El gradiente se utiiiza en el procesamiento digital de imagen para resaltar los bordes de una imagen; el gradiente es una función vectorial definida por:

y la magnitud es:

i Vf(x,y) 1 = 4 ( df/dx ) ( dfídy j

Computacionalmente la operación anterior es cara, por lo que se aproxima de la siguiente manera:

6

Page 7: MAGENES - 148.206.53.231

OPERACIONES GEOMÉTRICAS

Las operaciones geométricas son aquéllas que cambian las relaciones espaciales entre los objetos de una imagen, estas operaciones pueden cambiar de posición cualquier objeto perteneciente a una imagen. Así, pues, todo punto en la imagen puede moverse a cualquiera otra posición.

LA TRANSFORMACIÓN ESPACIAL

En el procesamiento digital, son requeridos dos algoritmos para hacer una operación geométrica. Primero un algoritmo que defina la transformacion espacial, este específica el movimiento de cada pixel desde su punto inicial hasta si1 posición final. La definición general para una operación geométrica es:

donde F(x,y), es la imagen de entrada y F(x,y) la imagen de salida. Las funciones a(x,y) y b(x,y) únicamente especifican la trancformacilán espacial

INTERPOLACIÓN BE LOS NIVELES DE GRIS

El segundo requerimiento para una operación geométrica, es un algoritmo para la interpolación de los niveles de gris, una vez que se cuente con una transformación espacial y un algoritmo de interpolación de niveles de gris, se podrá efectuar una operación geométrica. Generalmente el algoritmo de interpolación esta permanentemente establecido en el programa de la computadora. El algoritmo de definición de la transformación espacial, por el contrario, esta definido o especificado de forma única para cada aplicación.

TRANSFERENCIA BE LOS PIXELES

Para esta operación, existen dos métodos. uno puede verse como la operación de transferir los niveles de gris de la imagen de entrada a ¡a imagen de salida pixel por pixel Si im pixel de la imagen de entrada se mapea a i.4na posición entre cuatro pixeles de salida, entonces su nivel de gris es dividido entre los cuatro pixeles de salida de acuerdo a la regla de interpolación. Este método es conocido como “The pixel Carry Over“. Un método alternativo para implementai las operaciones geométricas es P I conocido corno. “The Pixel Filling”, en este caso, los pixeias de salida sori mapeados desde la imagen de entrada, uno a la vez, para establecer su nivel de gris correspondiente.

Si un pixel de salida estaba anteriormente entre cuatro pixeles de entrada, su nivel de gris es determinado por el algoritmo de interpolación.

7

Page 8: MAGENES - 148.206.53.231

OPERACIONES PUNTUALES

Las operaciones puntuales constituyen una simple pero importante clase entre las técnicas de procesamiento de imágenes. Estas permiten modificar el rango de nivel de gris de una imagen. Una operación puntual es por definición, una función que toma una imagen de entrada y tiene como salida, una imagen y como salida, otra imagen, en la cual los niveles de gris de cada uno de los pixeles de salida dependen únicamente del nivel de gris del correspondiente pixel de entrada. Además, en una operación puntual, cada pixel de salida correspondiente a un pixel de entrada determinado, tiene las mismas coordenadas. Así pues, una operación puntual no puede modificar las relaciones espaciales en las imágenes.

Resumiendo, las operaciones puntuales modifican las escalas de gris en una imagen. Estas pueden ser vista como si fuera una operación de copia pixel a pixel, excepto que los niveles de gris son modificados de una forma predeterminados.

Una operación puntual que toma de entrada un imagen A(x,y) y genera otra imagen de salida B(x,y) puede ser expresada matemáticamente como:

La operación puntual está completamente especificada por la función F(x,y) la cual especifica el mapeo entre el nivel de gris de entrada y el nivet de gris de salida.

USOS DE LAS OPERACIONES PUNTUALES

Las operaciones puntuales pueden ser usadas para eliminar los efectos de la digitalización no lineal. Otro uso de las operaciones es para transformar las unidades de las escalas de gris de la imagen en cuestión. Las operaciones puntuales son usadas principalmente para superar las limitaciones de los digitalizadores y de los dispositivos de despliegue.

Un usuario puede tener una imagen en la cual la presentacibn de interés ocupe un rango de nivel de gris relativamente pequeño. El puede usar una operación puntual para expandir el contraste de la parte de su interés, de manera que ésta ocupe el rango completo de nivel de gris.

OPERACIONES PUNTUALES LINEALES

8

Page 9: MAGENES - 148.206.53.231

Consideramos una operación puntual en la cual el nivel de gris de salida es una función lineal de nivel de gris de entrada. en este caso la ecuación sería:

Donde DB es el nivel de gris de salida puntual correspondiente a un punto de entrada que tiene nivel de gris DA . Obviamente, si a = I y b = O, tendremos la identidad, que sería la operación que sólo copiaria A(x,y) en B(x,y). Si ‘a’ es mayor que TI el contraste se incrementará en la imagen de salida. Para ‘a’ menor que ’I’ sucederá lo contrario. Si *a’ es negativo, las áreas oscuras se iluminaran y las partes luminosas se oscurecerán y la imagen estará “complementada”.

OPERACIONES PUNTUALES Y LOS HISTOGRAMAS

Los histogramas son una de las herramientas más simples utilizadas en el procesamiento digital de imágenes, un histograma se define de la siguiente manera:

Histograma Hjnivel de gris), es una función que muestra, para cada nivel de gris, el número de pixeles en la imagen que tienen este nivel de gris. La abcisa es el nivel de gris y la ordenada es la frecuencia de ocurrencia (número de pixeles)

Los histogramas tienen las siguientes propiedades:

1. Un histograma es único para una imagen particular. Esta propiedad es fácil de entender ya que el histograma de una imagen tiene un número H(D) de pixeles para un cierto nivel de gris (D) y la misma imagen no puede tener un H’(D) para el mismo nivel de gris (D).

2. Dos imágenes diferentes pueden tener histogramas idénticos. Suponga que se tiene una imagen rectángular y dividida en tres partes iguales coloreadas en distintos colores, y una segunda imagen de igual medida en los mismas colores pero en diferentes posiciones como se muestra a continuación:

A : Blanco, B : Amarillo, C : Rojo

Imagen 1 : B A R Imagen 2 : R B A

Es fácil ver que los histogramas de estas dos imágenes son iguales, puesto que en ambas imágenes tenemos el mismo número de pixeles de rojo, blanco y amai.illo.

9

Page 10: MAGENES - 148.206.53.231

La relación entre el histograma de la imagen de entrada y el de la correspondiente imagen de salida de una operación puntual F(x,y), esta dada por:

IO

Page 11: MAGENES - 148.206.53.231

OPERACIONES MORFOLÓGICAS

En morfología matemática existen dos operaciones básicas, la Dilatación y la Erosión. Los operadores morfológicos se pueden usar con dos operandos imágenes, la imagen que se va a procesar se le llama la imagen activa, y la otra imagen, la imagen núcleo se le llama imagen rejilla. Podemos modificar la imagen activa utilizando varias rejillas diferentes.

Para poder definir de manera más clara las operaciones morfoiógicas se hará uso de la siguiente simbología:

Z Z2

A,B,C,X,Y ... : x '.-.I Y x 7 Y x 1; Y Y

Xb

Conjunto de todos los enteros. Imagen binaria en 2 - dimensiones. Subconjuntos de 2 . Unión de conjuntos. Intersección de conjuntos. X subconjunto impropio de Y. Reflexión del conjunto X con respecto al origen, es decir, el conjunto de puntos tales que -x 6: X Traslación de X por el vector b, es decir (x : x-b -: X}

Definición de la suma y substracción de conjuntos Minkowski.

Suma de conjuntos:

Resta de conjuntos:

Donde T es la imagen rejilla.

Algebraicamente la Erosión y Dilatación se pueden expresar usando la substracción y adición de conjuntos Minkowski.

E rosió t i

Page 12: MAGENES - 148.206.53.231

La Erosión de X por T. se define corno el conjunto de puntos x tales que la traslación Tx esta contenida en X. Se expresa como:

Uno de los usos de la Erosión es el de adelgazamiento de una imagen

Algunas regillas utilizadas para la Erosión son:

‘ 1

Rejilla 1 = íl

I

I C )

: o I o

r

1 ( 1

( 1 i l

Rejilla 4 = i 1

12

Page 13: MAGENES - 148.206.53.231

1 1 1 I 1 ’ 1 1 1 1 1 1 ,

Rejilla 6 = 1 1 1 1 1 1 I O o u O O ‘ i o o i! (1 0 :

-

1 O í! ‘ 1

r l 1 ; I 1 1 o I‘

Rejilla 7 = 1 1 1 0 1)

1 1 1 0 0 1 0 9 I , 1 1

‘ 1 1 1 1 1 ’ I 1 1 1 1 1

Rejilla 8 = 1 1 1 1 1 ’

I 1 1 1 1 1 ’ 1 1 1 1 11

1 1 ct: 1 1 1 1 1 I ’

Rejilla 9 = 1 1 1 1 1 1 1

‘-0 1 1 1 c i i

i 8 9 1

‘ 1 1 I 1 1 ,

Dilatación

La Dilatación de X por T se define como el conjunto de todos los puntos x tales que Tx intersecta X. Se expresa como:

Con la Dilatación se puede lograr conectar una imagen “desconectada”, por ----------- , que después de la aplicación del ejemplo una línea desconetada es:

operador Dilatación se espera obtener una línea conectada, osea - -- -

La Erosión y Dilatación junto con operadores de conjuntos se utilizan para el reconocimiento de patrones.

Para la Dilatación se utilizan las mismas rejillas definidas en páginas anteriores.

13

Page 14: MAGENES - 148.206.53.231

FILTROS

Una imagen contaminada al momento de digitalizarse o por contaminación en el ambiente al momento de tomar la fotografía puede ser parcialmente descontaminada utilizando los filtros pasa-baja y pasa-altas.

Filtros pasa-baja

Ei filtro pasa-baja atenúa las altas frecuencias dejando pasar únicamente las bajas. Se supone que las altas frecuencias son producidas por la contaminación (ruido) y los contornos bien definidos, el filtro pasa-baja tiene la virtud de producir imágenes borrosas.

Para cada pixel de la imagen activa, se calcula el valor promedio tomando en consideración sus vecinos. Los filtros pasa-baja conocidos son aproximaciones de una distribución gaussiana. Para el caso discreto, los filtros corresponden a máscaras de convolución que determinan el nuevo valor del pixel con respecto a sus vecinos:

- 1 ' r , I 1

I i 1 1 , Filtro i , 1!9 I 1 1 1

r l 1 1 Filtro 2, 1/10 ' 1 2 I

I 1 1 1

Correspondiontes en general al cáicuio de la media. La respuesta de la máscara es mejor cuando se aproxima a una campana de Gauss. un operador para una máscara 5 x 5 es:

1 1 1 1 1 : 1 -

1 2 I -

1

1

ri - ,7 4

,-l

Filtro 3, 1/38 I I 2 4 2 1 : -7

I 1 1 1 1 I

Filtros pasa-alta

lnversamente al filtro pasa-baja, este filtro se caracteriza por ia atenuación de las bajas frecuencias dejando pasar las frecuencias altas. Debido a que las altas

14

Page 15: MAGENES - 148.206.53.231

frecuencias representan los contrastes pronunciados. los filtros pasa-alta realzan los contrastes en la imagen y por esto se realza el rüido de la señal.

Por sus características, esta operación de filtrado equivale a la diferenciación espacial. En analisis de imágenes, este filtro corresponde a los operadores de extracción de contraste concéntricos y opuestos que algunos autores asocian a la respuesta del Sistema Visual Humano.

En el caso discreto, se aproxima la función de filtrado de altas frecuencias por las siguientes máscaras de convolución. Algunas máscaras que aproximan esta función son:

I -1 Filtro 2 - I -1

- 1

-

' 1

! I

- { I

Filtro 3 -

I 0 ' 5 -1 - 1 0-

1 11 9 - 1 1 li

-2 1 ' 5 -2

1 ;

-

7 -

Es conveniente que para realizar la convolución en un dominio más amplio es recomendable el cálculo en el dominio de Fourier.

15

Page 16: MAGENES - 148.206.53.231

ORGANIZACIÓN DEL PROGRAMA FUENTE

Este programa se diseño para operar en una computadora del tipo PC con ¡as características mínimas de:

Procesador : 80206 Memoria : 2 Megabytes. Monitor : WGA Modo de vídeo 13h.

Todos los programas están compilados en Turbo Pascal Versión 5.5. En algunas rutinas básicas se utiliza lenguaje ensamblador.

El conjunto de programas que componen el sistema de procesamiento digital de imágenes esta compuesto por cinco grupos de programas donde se implementan las operaciones básicas: aritméticas, geométricas, puntuales, morfológicas y filtros del procesamiento digital de imágenes. También se diseñaron varias librerías para el manejo de los dispositivos de la computadora. Las librerías están organizadas en seis grupos de programas.

OPERACIONES BAS ICAS .

ARITM ÉTICAS

El conjunto de programas que implementan las operaciones aritmeticas entran oiganizadas en ptocedimientos separados, o sea una rutina o un conjunto de rutinas independientes.

GEOMÉTRICAS, PUNTUALES, MORFOLÓGICAS Y FILTROS

El conjunto de programas que implementan las operaciones geométricas, puntuales, morfológicas y los filtros se encuentran organizados en procedimientos separados al igual que las operaciones aritméticas.

Li BRE R I AS

I . LIBBAS Librería para el manejo de imágenes en vídeo y disco Las imágenes son desplegadas en el monitor utilizando el modo dé video 13h. En esta librería se encuentran las rutinas para las llamadas al BIOS que programan el modo de vídeo, el manejo de la paleta de colores, etc. Ejemplo de algunas rutinas son las siguientes:

Page 17: MAGENES - 148.206.53.231

Pone 31 monitor en el modo 13h 7 Frocedure PonModo320~200-256,

i" Pone al monitor en el modo 3h *} Procedure Regresa AModoTexto:

r inicializa la Paleta. para el manejo de 64 tonos de Gris. 7 Procedure Inicia I iza Paleta, 3

En esta misma librería se definen las rutinas de manejo del disco para lectura y grabado de imágenes, por ejemplo, nos encontramos rutinas como:

Lee una Imagen de Disco *> Procedure Leelmagen(Var h a g Imagen, NomArch String),

Salva una imagen en Disco 7 Procedure Escribelmagen(1mag: Imagen; NomArch: String);

2. LIBFONT Librería donde se encuentran definidos el conjunto de caracteres ascii, que se utilizarán en los textos que aparecen en las ventanas y menús. Cada caracter se define en una matriz de 8 x 8 pixeies. Algunas de las rutinas que aparecen en esta librería son:

3. LIB-MENU En esta librería se encuentran definidas todas las características de los menús y la manera de manejarlos. Se especifica los tonos de gris utilizados para el desplegue de los menús. La forma del menú: vertical o orizóntal, etc. En esta librería nos podemos encontrar rutinas como las siguientes:

p* Inicializa un menú **> Procedure Mopen;

i"* Termina un menú **} Procedure Mclose;

r* Muestra una cadena de caracteres en un menú *? Procedure MwriteStr(St: Stringj,

r* Limpia el rectángulo especificado por los parámetros **) Procedure ClearMenuRegion(x1 .y1 ,xZ,yZ,Color. byte);

4. LIB-SEC interactuar con el usuario, mostrar mensajes y otros:

En esta librería se encuentran definidas rutinas para

y* Obtiene una cadena de caracteres proporcionado por el usuario **}

17

Page 18: MAGENES - 148.206.53.231

Function TraeNombre. String:

(" Interroga al usuarÍo si desea salvar una imagen *y Function Deseasalvar: Boolean:

?* Regresa verdadero si el usuario acepta la interrogante **} Function ConfirmacioníNom: String): Boolean;

5. LIB-SEL usuario a seleccionar imágenes de disco.

En esta librería se encuentran las rutinas que ayudan al

6. LIB-VENT El manejo de las ventanas en modo gráfico 13h se encuentra definido en esta librería. Se definen las características de la ventana como el número máximo renglones, número máximo de columnas, niveles de gris utilizados el los marcos y fondo, etc. También se específica la manera que se mostrará una imagen en el interior de una ventana.

18

Page 19: MAGENES - 148.206.53.231

......................................................................................... \

r Autores: Jorge Higareda y José Antonio LÓpez Posada 7 (* Asesor: Dr. Octavio Arzate S. 3

7 Lic. en Computación 7

9 i,***t*t***********t***********t*****l*************i~~********.k************~***~******** 1

-y Menu Principal del Sistema PROCESAMIENTO DIGITAL DE IMAGENES 4

'Y c*

Proyecto de Investigación. Universidad Autonoma Metropolitana

($O+, F+} Program Menu; Uses Lib-Menu, Lib-Bas, Over!ay, MenuOvr, Pdi-Path: Pdi-Desp: Pdi-Dir, Pdi-Grad: Pdi-Mag : Pdi-RefV, Pdi-Ref H, Pdi-Cont, Pdi-ex, Pdi-Com p, Pdi-tras, Pdi-Suma, Pdi-Rest, Pdi-ivlasc, Pdi-Mult, Pdi-CMas, Pdi-Dist, Pdi-FMed, Pdi-Rota, Pdi-Div, Pdi-Ofmt, Pd i-P Alt, Pd i-PBaj , Pd ¡-Di la, Pd i-Eros; {SO Pdi-Path} {$O Pdi-Desp} {$O Pdi-Di} @O Pdi-Grad} {$O Pdi-Mag} {$O Pdi-RefV) {$O Pdi-RefH} {$O Pdi-Cono {$O Pdi-Esc} {SO Pdi-Comp} {$O Pdi-Tras} $2 Pdi-Suma} {$O Pdi-Rest} {$O Pdi-Macc} {$O Pdi-MuIt) {$O Pdi-CMas) {$O Pdi-Dist} {$O ?di-FMed} {$O Pdi-Rota) {$O Pdi-Div) {SO Pdi-Ofmt} {$O Pdi-PAlt} {$O Pdi-PBaj) {$O Pdi-Eros) {SO Pdi-Dila)

Var P/lI,M2 Gmenu, O1 ,O2 Longlnt, 0 3 Longlnt, M3 Gmenu Band Boolean.

Procedure Presentacion Var M3 Gmenu

beg in tecla byte

With M3 do beg in

M I n it (4,2,34, I 2, N o 0 rie n t) , Mitem(l3,10,'Enter',l ,O), Mopen MPutFrame,

20

Page 20: MAGENES - 148.206.53.231

MwriteStrXYColor(l~2 UAM-I Lic. en Computacion'.h/lForeSround); ivlwriteStrX'ÍColor(1,3 , I Procesamiento Digital'.Rojjoj; MwriteStrXYColorjl%4 ,' de Imagenes': Rojo); MwrtteStrXYColor(l.6 ,' Alumnos:',Amarillo): MwriteStrXYColor(ll.6:' Jorge Higareda'.O); MwriteStrXYColor(1 I >7,' Jose A Lopez',G); M w r i test rXY Co I or( 1 ! 8 : Ase sor . ' : Am a r i I I o) I MwriteStrXYColor(l1 , € % : I Dr. Octavio Arzate'.G): MwriteStrXYColor(1. I O.' Presione'.Amarilloj: Tecla,= LeeEspecial([ENTl1); M c ! os e ;

end; end;

c' Presentacion

begin 02:= 1; O 1 = I; 03:= 1 ; Band:= True; PonModo320x200-256; InicializaPaleta; Presentacion; Repeat

VisualizaPagina(0). if Band then beg in

M I .Mlnit(l ;I :40,1 ,Horizontal); MI Mltem(1 : I , 'Varios',lc6); M I .Mltem(lO,l ,'Aritm ',2>6); M I .Mltem(l6,1 ,'Geom',3,6), M I .Mltem(24, I ,'Puntual',4,6), MI .Mltem(33,1 ,'FIltra':5.6); M I .Mopen;

end; O1 := M1 .MSeiect; if (01 O) then begin

Case01 of VARIOS *}

I. begin M2. Mi nit( 1 ,2,8,7 ~ V e rticai) ; M;Z,Mltem(l,2,'Path ' . I 1 ,MForeGround); M2. Mltem(1 ;3;'Dir ';I 2,MForeGround); M2.Mltem(l,4,'Desp ',I 3,MForeGround); M2. Mltem(l,5,'0. Fmt', 14, MForeGround); M2.Mltem(l ,6,'Salir',IS,MForeGround);

end: C ARITMETICAS 3

2: begin M2.MInit(9,2,17,13,Verticai): M2.Mltem(l,2. 'GRAD '.21 ,MForeGround): M2.Mltem(l:3. 'Suma ',22;MForeGround): M2. Mltem(l,4, 'Resta ',23,MFcreGround); R'l2.Mltem(l,5: 'Mdt ',24,MForeGroundj; M2.ILlItem(l,6: 'Div ':25:MForeGround), M2. Mltemjl:7. 'Masc l . 26, MForeGroundji

21

Page 21: MAGENES - 148.206.53.231

h42 Mltetn(l!8, 'Comp M',27,MForeGround), M2.Mltem(l ,I O, 'DiIata',28,hilforeGroundj. Pv'i';12.~lltetn~l~1 1 ,'Erosio',iS,MForeGroundj:

end: C GEOMETRiCAS 7

3: begin M2. Minit(l7,2,26,7,Vertical); M2. Mitem(l,2:'Rota ', 37 MForeGround); M2. Mltem(l,3.'Magnif ';32: MForeGround): M2 Mltem(l,4,'Refle V'.33,MForeGround), M2.Mltem(l,5,'Refle H',34,MForeGround); M2.Mltem~l,6,'Traslac',35,MForeGround);

end;

4: begin (* PUNTUALES *}

M2,R/llnit(23,2,32,6,Ve~¡~al~; M2.Mltem(l ,Z,'Cont ',41 ,i\;lForeGround); M2.Mltem(l,3;'Escala ',42,MForeGround); M2. M Item (1 ~ 4 'Com p ': 43, M ForeG rou nd) . M2.Mltem(l,5;'Dist ',44,MForeGround):

end;

5: begin (* FILTRAR *}

M2.Mlnit(31.2.40.5.Vertical): M2. Mltem(l,2,'Med 3 ~ 3 . 5 1 : MForeGround); M2. Mltemjl,3,'P Aitas',52, MForeGraindj; M2.i\Jlltem(7 :4,'P Bajas':53,MForeGround);

end: end: M? MOpen; M2. tnPutArrow, if O1 = 2 then M2. tr;WriteStrXYColor(l ,S,'-Morfo-',Oj, 02:= M2. MSelect; M2. MClose; if (02 O) then begin

M.l .h'lCiose; Case 02 Of c* VARIOS *)

I I : -Pdi-Path: 12: -Pdi-Dir; 13. -Pdi-Desp; 14: -Pdi--Ofmt, 15: begin

RegresaAmodoTexto, Ex¡'.

L ,

end;

ARITMETICAS *) 21 -Pdi-Grad 22 -Pdi-Suma 23 -Pdi-Rest, 24 -Pdi-Mult 25 -Pdi-Div 26 -Pdi-Masc 27 -Pdi-CMas 28 -Pdi-Dila, 29 -Pdi-Eros,

22

Page 22: MAGENES - 148.206.53.231

end else begin

end;

SEQMETRICAS 7 31. -Pdi-Rot¿i; 32. -Pdi-Mag: 33: -Pdi-RefV; 34. -Pd i-R ef H : 35: -Pdi-Tras;

41 : -Pdi-Cont, 42: -Pdi-Esc: 43, -Pd ¡-Corn p: 34. -Pdi-Dist; 45:; 46.

51 : -Pdi-FMed: 52: -Pdi-PAlt; 53: -Pdi-PBaj;

PUNTUALES '3

FILTROS *}

end: Band:= True;

end else

Band:= False

h1S Mlnitjl U 5,26 8,Horizontal), M3 Mltem<5,3 'No' I ,IVlForeGround) M3 Mltem(lO,3 'Si' 2 MForeGround) M3 Mopen M3 mPutFrame M3 MVVrrteStrXYCoior(G,Z,'Salir ?',Rojo), 0 3 = M3 Mselect M3 Mcloce if 0 3 = 2 then M I mClose else Band = False

Until (o3 = 2), HegresaAmodoTexto.

end

23

Page 23: MAGENES - 148.206.53.231

y** OPERACIONES ARlTMETlCAS **? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *-,

y IJAM-I Lic en Computacion 3 1 *;

3

1

{* Provecto Procesamiento Digital de lmaqenes (PDI) *)

r*

Calcula el Gradiente de una imagen C***t***f*ifT***t-h***i*t***********************~***~~*~*i**i~* 'A

{SF+ O+> Un it Pd i-G rad Interface PI ocedu ;e -Pdi-iJ;ad, Implementation Uses Lib-Bas Lib-Se1 Lib-Vent, Lib-Sec

Procedure GradienteUmgF. Imagen; Var ImgD. Imagenj, Var x.y: Word;

begin dx, d y: Word.

for y:= O to MAX-Y do for x.= O to MAX-X do begin

if (y=O) or (y= MAX-Y) or (x=Cl) or (x= MAX-X) then

else ImgDA[y,x].= O

begin dx:= lmgF"[y,x+l] - ImgF"[y,x-I]; dy:= ImgFA[y+l :XI - ImgFA[y-l ,XI; lmgD"[y,x]:= Round(sqrt(dx*dx+dy*dy));

end; end,

end: yGradiente*}

Procedure -Pd i-G rad, Var S Selection,

Fuente Destino String ImagenF ImagenD Imagen Tecla byte, n W e , W GVVindow

begin Fuente = S sSelect(1 1 ,'lmageii if Fuente <> " then begin

AsignaMemoria(1magenF) Asig naMemoria(!magenD) Leelmagen(lmagenF,Fuente+' ima'), ¡vlapealmagen(lmagenF, PAGINSO), VV winit(l,25 40,25,Falsej, W wOpen W wCursorOff, W wWriteStrCoior( Gradiente - TRABAJANDO ' Amariiloj, Gradiente(1magenF ImagenD) Ma pea I m a g e n ( I mag en D P AG I N A-I )

24

Page 24: MAGENES - 148.206.53.231

W wClose VisualizaPaginajlj, n = O, Repeat

Tecla = LeeEspecialJ[ENT E X ] ) if Tecla = ENT then begin

VisualizaPaginajn), if (n = 3 ) then n = U else n = I

end Until Teela= ESC VisualizaPaginajl) it Deseasalvar then begin

Destino = TraeNombre + ' Ima' if LengthiDestino) = 4 then

If Not ExisteArchjDestino) Then

else E sc r i be I mag en (I mag en D , Dest i no)

if ConfirmacioníDestino) then Escribelmageti(lmagenD,Destitio]

end, Li beraMemoria(lmagenD), Li beraMemoria(1 mag en F)

end end C -Pai-Grad 3 beg in end

Proyecto Procesamiento Digital de lmagenes (PDI) *} IJAM-I Lic en Compiitacion *7 r *>

Suma de aos imagenes *I 3 .............................................................

{SF+ O+} I Jnit Pdi-Suma Interface Procedure -Pd i-Suma, Implementation Uses Lib-Bas, Lib-Se1 Lib-Vent Lib-Sec

Procedure SumajlmgA, imgB Imagen Var ImgC Ímagenj Var x,y Word,

begin Aux Integer

for y O to MAX-Y do for x = O to MAX-X do begin

Aux = IingAA[y x] + ImgB*[y,x] if ( A m = 63) then ImgC"[y x] = 63 else

if (Aux < O) then ImgC"[y,x] = O else

25

Page 25: MAGENES - 148.206.53.231

!mgC"[y x] = 4.u:: end,

end. (* Suma *}

Procedure -Pdi-Suma; Var S. Selection,

FuenteA, FuenteB, DestinoC. String, ImagenA.lmagenB.lmagenC. Imagen: Tecla, byte, n: Byte; W. GWindc,.,

FuenteA:= S.sSelect(1 ,I 'Imagen A'); if FuenteA if (FuenteA ..c> ' I ) And (Fuente6 .--= ") then begin

AsignaMemoria(1magenAj; AsignaMemoriajlmagenB) AsignaMemoriajlmagenC); Lee I mag en (Image t i A, Fue tite A+'. i tn a') ; LeelmagenjlmagenB. FuenteB+'. ima'); Mapealmagen(lmagenA,PAGINA-O); VisualizaPaginajl); Rilapealmagen(lmagenB,PAGII\IA_l): W.wlnitjl,25,40,25,Falsej; W. w0pen: W. wCu rsorOff; W.wWriteStrColor(' Suma de dos lmagenes - TRABAJANDO I . Amarillo): C u ma (imagen A : imagen 6, I mage n C) I blapeal inagen ( I inagenC, PAGINA_2j, VV. wllose; VisualizaPagina(2): n:= O; Repeat

bent?

" then FuenteB:= SsSelect(1 ,I .'Imagen B'):

Tecla:= LeeEspeciaI([Er\.lT,ESC!); if Tecla = ENT then beg in

VisualizaPagina(n): Case n Of

O n.= 1. I n .= 2; 2 : n.= O ;

end; end;

Until Tecla= ESCi \i i su a I iza P a g i n a (2) ; if Deseasalvar then begin

OestinoC-= TraeNcmbre + '.¡ma1; if Length(DestinoCj 4 then

If Not ExisteArch(DestinoCj then

else Eccribelmagen(ImagenL,DestinoC)

if ConfirmacionjDestinoC) then Escribelinagei7jimagetiC: DestinoC):

end; Li beraMemoria(1magenA):

Page 26: MAGENES - 148.206.53.231

L i be ra Me m or I a (I m age n E) LiberaMemoriajlmagenLj,

en# end Y -Pdi-Suma 7 begin end

.............................................................. 7

r UAM-I Lic en Computacion 1 r 7 r Resta de dos lmagenes *} ................................................................. J

@F+,O+}

Proyecto Procesamiento Digital de lmagenes (PDI) *7

Unit Pdi-Rest I n te rface Procedure -Pdi-Rest I m plementation Uses Lib-Bas Lib-Set, Lib-Vent, Lib-Sec

Procedure Resta(lmgA lmgB Imagen \dar lmgC imagen) Var x y Word

Aux Integer,

far y = O to MAX-Y do for x = O to M A X X do begin

begin

AUX = ImgA"[y,x] - ImgBAíi).,xl, if (Aux > 63) then ImgC'[y x] = 63 else

if (Aux .c O) then ImgC'[y x] = O else

ImgCAjy,x] = Aux end,

end, Resta 3

Procedure -Pdi-Rest, Var S Selection,

FuenteA FuenteB DestinoC String ImagenA ImagenB ImagenL Imagen Tecla byte, n Byte, W GWindow,

FuenteA = S sSelect(1 ,I 'Imagen 4') if FuenteA .=: ' I then FueriteB = S sSeIect(1 , I 'Imagen a') if (FuenteA <> ") And (FuenteB <:- "j then begin

AsignaMemoria(lmagenA\ Asigna Me moria (I mag en B) Asi g n a Me mo ri a < I may en U) , Leelmagen(imayenA FuenteH+' irna'), Leelmagen(lmagenB Fuenteti+' ima')

begin

27

Page 27: MAGENES - 148.206.53.231

PA a pea I mag en ( I ma ge n .A, P AG ! N d-O) : VisualizaPaginz(7); MapealmagenílmagenB, PAGINA-! ); vV.wtnitjl,25.40.25.False); vv \vepen. WLwCursorCiff; VV.wWriteCtrZolorí' Resta de dos Imagenes - TRABAJANDO...': Arnarilioj, Resta ( I may en H I I mag en B, 1 mag en e) I Mapealmagen(lmagenC.PAGINA-2). W wClose' 'JisualizaPagina(2); n.= O ; Repeat

Tecla: = LeeEspeciai([ENT, ESC]]: if Tecla = ENT then begin

VisualizaPayinaín); Case n Of

O . n:= 1; I n:= 2: 2 ' n.= 0:

end; end;

Until Tecla= ESC, VisualizaPagina(2); if Deseasalvar then begin

DestinoC:= TraeNoinbre + '.lina'; if Length(DestinoC) =. 4 then

If Not ExisteArchjDestinoC) then

else Escri belmagen(lmagenC,DestinoC)

if ConfirmacionjDestinoC) then Escri belmagen(lmagenC,DestinoC):

end; Libera M e m oria (I m age n A) ; LiberaMernoria(lrnagenBj, Li beraMemoria( ImagenC):

end; end; c* -Pdi-Rest *} begin end.

1 c************t********i******t*****~***~*~*******~**~**t****~~*** *

UAM-I Lic en Cornputacion *) c* 3 r Multiplicacion de dos lmagenes 3

3 {$ F+, O+} Unit Pdi-MuIt Interface Procedure -Pdi-MuIt, Implementation Uses Lib-bas Lib-Sei, Lib-Vent. Lib-Sec

c* Proyecto Procesamiento Digital de lmagenes (PDI) *)

(**CCt*Xlx**C~***X******i*fl******t******W************k*~***W*~*~ I

28

Page 28: MAGENES - 148.206.53.231

Procedure ivlultrplicacionjImgA imgB imagen 'dar ImgC Imagen) Var x,y Word

beg in Aux Integer

for y = O to MAX-" do for x = O to MAX-X do beg in

Aux = ImgA"[y x] * ImgBA[y x] if (Aux else

63) then ImgCA[y,x] = 63

if (Aux < O) then ImglA[y,x] = O else

imgCA[y x] = AUK end;

end; Multiplicacion *}

Procedure -Pd i-M u I ti Var S: Selection;

FuenteA,FuenteB,DestinoC. String, ImagenA.lmagenB,lmagenC: Imagen: Tecla: byte; n: Byte: W. GWindow;

FuenteA:= S.sSelect(1 ,I .'Imagen A'j: if FuenteA O " then F~ienteB:= S sCelect(1 ,I .'Imagen B'i. if (FuenteA <> ' I ) And (FuenteB ,<: ") then begitn

4signaMemoria(lmagenA)i AsignaMemoria (ImagenB): AsignaMernoriajlmagenC): Leelrnagen(lmagenA;FuenteA+' ima'); ieeimagen(lmagenB,FuenteB+'.ima'), Mapealmagen(lmagenA,PAGINA-@); VisualizaPagina(1 f: Mapealmagen(!magenB. PAGINA-I); VL'.wlnitfl,25,40,25,False); WwOpen; \1\1 .wi; u rsorOff; W wWriteStrColor(' Multiplicacion - TRABAJANDO ' , Amarillo): I\?lultiplicacion(lmagenA. ImagenB.!magenC). Mapealtnagen(it~iagefiC,PAGINA2jl irJ. wClose. VisuaIizaPaginajZ); n:= O; Repeat

begin

Tecla:= LeeEspec!ai([ENT, ESC]); if Tecla = ENT then begin

VisualizaPagina(n); Case n Of

O : n:= I; I : n:= 2, 2 . n.= O;

end:

29

Page 29: MAGENES - 148.206.53.231

end Until Tecla= ESC, VisualizaPagina(2) if Deseasalvar then begin

DestinoC = TraeNombre + ' Ima', if LengthíDestinoCj -. 4 then

If Not ExisteAich(DestinoiJ) then

e k e Escribelmagen(1magenC UestinoC)

if CcnfirmacionIDestinoC) then Escribelmagei~(lmageriZ, DestiiioS),

end, L i be ra hile m o ri a ( I mag en A) Liberah/lemoriaílmagenE), LiberaMemoriajlmagenCj,

end, end, Y -Pdi-MuIt begin end

1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

(* UAM-I Lic en Computacion 7 (*

I ............................................................. *

{SF+, O+} Unit Pai-Div I n te rfa ce Procedure -Pdi-Dfv, Irnplementatioii Uses Lib-bas Lib--Sel, Lib-Vent, Lib-Sec

Proyecto Procesamiento Digital de Imageries (FDI)

*l 7 Division de dos lmagenes

Procedure Division(!mgA: ImgE: Imagen. Var !tngC. Imagen); 'dar x,y: Word;

begin Aux: integer;

for y:= O to MAX-Y do for x:= O to MAX-X do begin

if ImgB"íy,x] <> O then

else Aux:= ImgAA[y.x] div ImgB*[y,x]

Aux.= o; if jAux > 63) then ImgP[y,x]:= 63 else

if (Aux < O) then ImgCA[y XI:= O else

ImgC"[y,x]:= Aux; end:

end; (" Division *)

30

Page 30: MAGENES - 148.206.53.231

ProcedLirí! -Pdi-Div, Var S. Selection;

FuenteA, FuenteB, DestinoC: String: ImagenA ImagenB,lmagenC: Imagen. Tecla: byte; n. Byte, VV. GWindow.

FuenteA.= S.sSelect(1 .I ,'Imagen A'): if FuenteA " then

if (FuenteA O- ") And (FuenteB c> ") then begin

AsignaMemoria(lmagen,4): AsignaMernoria(lmagen6); As ig ti a ivl e mor i a (I m age nC) , Leelmagen(imagenA,FuenteA+'. ima'j; Leelmagen(lmagenB.FuenteB+' ima'); Mapealmagen(lmagenA, PAGINA-O): VisüalizaPagina(1); Mapealmagen(lmagenB,?AGINA-'I); W.wlntt(l,25,40.25,False); W wOpen; W wCursorc3ff; l~~:,~vLZIriteStr~olorj' Division - TRAGAJANGS. . . l . Amarillo); DivisionjlmagenA, ImagenB.lmagenC}; Mapealmagen(1magenC; PAGINA-2). W wClose: VisualizaPagina(2); n:= O; Repeat

begin

FuenteB = S.sSelectj1 ,I ,'Imagen 5'):

Teda.= LeeEspecial([ENT;ESC]): if Tecla = ENT then begin

Visua!izaPagina{n)i Case n Of

O n:= 1; 1 : n.= 2: I ? n:= o:

end; end,

üntil Tecla= ESC; VisualizaPagina(2); if Deseasalvar then begin

DestinoC:= TraeNombre + '.lma': if Length(DestinoC) > 4 then

If Not ExisteArch(DestinoC) then Escribelrnagen(lmagenC, Desti noS)

else if ConfirmacioníDestinoC) then

Escribelmagen(lmagenC,DestinoC), end; L i hera Memoria ( I m age n .A) : LiberaMemoria(ltnagen6): LiberalLlemoria(imagenC); end,

end:

Page 31: MAGENES - 148.206.53.231

1 Proye& Procesamiento Digital de Iinayenes (PGlj 7

i' JAM-I Lic err Cornputacion '1 Y (*

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . * 1

*l Genera la Mascarilla de Una Imagen .-; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i {$F+ O+} ü n it Pd i-Masc, Interface Procedure -Pdi-Masc I ~I-I pl e rn e n ta t i on Uses Lib-Bas Lib-Se}, Lib-Vent, Lib-Cec,

Function Mask(Var ImgM. Imagen!. Boolean Const F I ecii a M as k. ,4 r ra) I , [G..5; C..5] of Char = (

' xxxx ' , 'xx ' X X ': ' X X', I ,

), Var DisMask Boolean,

x y Dir-di Word, FlechaArr Array [O 5 Cl 51 Cf Byte Tecla Byte

Procedure PonEn(x,y Word) Var I J Word, begin

For j = O to 5 do For i O to 5 do begin

FlechaArrD,i] = LeePixel(Dir-di y+j, x+i) if FlechaMask[l,i] = ' X then

else Escri bePixelkDir -ai, V+J x+i, 0)

EccribePixel(Dir-di y+] x+i 63) end end PonEn *)

Procedure QuitaDejx y Word), Var I J Word begin

For J 0 to 5 do For i = O to 5 do

EscribePixeltDir-di V+J x+i FlechaArrÚ,~]) end

begin QuitaDe *}

Mask = FALSE DisMask = FALSE

32

Page 32: MAGENES - 148.206.53.231

x-= o: Y = o Case'PAG-ACT of

O Dif-di.= 8OOOOi 1 : Dir-di:= $4000; 3 L : Dir-di.= $8000. 3 : Dir-di.= $cU00:

end; Pon En (X,Yj, Repeat

Case Tecla Of Tecla.= LeeEspecialjEFI , F-IZQ. F-DER. F-.ABA. F-ARR ESC, ENTII).

F1 begin Write(%), DisMask:= Not(DisMask);

end; F-DER . begin

Qu itaDe(X.Y) ; if DisMask then begin

if LeePixel(dir-di,y x) 100 then begin I mg M $' [y, x] : = Lee P ixe I (Di r-d I, y, x) ; EscribePixel(Dir-di,y,x. 100); end:

end else if (ImgM"[y,x] C- 0) then begin

EscribePi>teiiDir-.di,y,x: ImgM"[y,x]): ImgM*[y:x]:= O;

end; I n c(X) , P0nEníx.y):

end; F-IZQ : begin

QuitaDe(X,Y), if DisMask then beg in

if 1.eePixelídir-di.y.xj ~ 3 . 1 O0 then begin ImgM"[y,x]:= LeePixel(=ir-di,~,x): EscribePixei(Dir-di,y,x. -1 OOj, end:

end else

if ImgM"[y,x] O O then begin EscribePixel(Dir-di. y,x; ImgM"[y.xJ); ImgM*[y,x]:= O: end;

Decíxj; PonEn(x, y):

end: F-A9.A : begin

Q u ita De {X , Y) ; if DisMask then begin

33

Page 33: MAGENES - 148.206.53.231

if LeePixeijdir-di,y,x) <> 100 t h e n begin imgM"[y,x]:= LeePixel(Dir-di,y,n, EscribePixel(Dir-di:y,x, 100); end.

encf else

if {ImgM"[y.x] .ci U) then begin EscribePixeljDir~di,~',x.IrngM*[y.x]): I m g M A [y, x] : = O; end:

W Y ) , PonEn(x,y):

end; F-ARR : begin

QuitaDe(X,Y); if DisMask then begin

if LeePixel(dir-di,y,?) <:> 1 O0 then beg i t-i ImgM.'[y,x]:= LeePixeljDir-di,y,x), Escri bepixel (Dir-di , y,x, 100); end:

end else

if ImgM"[y,x] C- O then begin EscribePixel(Dir-di, y.x,lmgM"[y,x]); ImgMA[y,x].= O: end;

Deciy); Pon En (x, y):

end; ESC :Begin

QuitaDe(x, y); Exit;

end: end; Until Tecla = ENT;

Quita De (x, y) : Mask:= TRUE; For y:= O to MAX-Y do For x:= O to MAX->( do if ImgMA[y,s] 'c= O then ImgM"[y,x]:= 1,

end; (* Mask *)

Procedure InicializaMask{Var Img Imagen) Var y x Word, begin

For Y = O to MAX-Y do For X = O to MAX-X do

Irng"[y Y.] = o end {* IncializaMask *}

34

Page 34: MAGENES - 148.206.53.231

Procedure -Pd I-Masc. Var S. Selection:

Fuente,Destino: String; I mag e t i F ~ I mag en D : I mag en ; n: Byte] Tecla: Byte; W: Gwindow:

Fuente:= S.sSelectj1 .I ,'Imagen ?'j: if Fuente .c> I ' then begin

begin

4signaMeinoriajlmagenF); As¡ g n a Me m o r i a( I mag en D) ; Leeimagen(ltnagenF, Fuente+'. ima'j; Mapealmagen(lmagenF,PAGINA-O); W wlnit(l,25.18.25.False): W. w0pe n ; W. wCu rso rOff; \N . wW ri test r Colo r ( I n ici a I iza n do. . . I , A ma ri I I o j 1 InicializaMask(imagenD), w wClose; if Mask(lmagenD) ,4nd Deseasalvar then begin

Destino:= TraeNombre + '.¡ma'; if Length(Destin0) =. 4 then

If Not ExisteArchíDestino) then

else Eccribelmagen(lmagenD,Destino)

if Confirmacion(Destinoj then Escribelmagen(lmagenD. Destino);

end; Li be ra 1\4 e mo ri a (I m age n D) ; Li beraMemoriajlmagenF);

end; end;

begin end.

-Pdi-Masc 3

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . y! J

Proyecto Procesamiento Digital de lmagenes (PDI) *} (* UAM-I Lic en Computacion 7

*) 7 1 Ct***************t********t*t***********t*t********************t *

Filtro Media Aritmetica con Ventana de 3x3

{SF+.O+} Un it Pd t- FMed, i n te rface Procedure -Pdi-FMed, I tn p I e m e ntation Uses Lib-Bas, Lib-Sel, Lib-Vent, Lib-Sec,

35

Page 35: MAGENES - 148.206.53.231

Procedure Media(lmgF Imagen, Var lmgij Imagen), Var x y Word beg in

for y = O to MAX-Y do fcr x = O to MAX-X do beg ¡ n

if (y = O) or [x = O) or [y = MAX-") or ( x = MAX-X) then ImgDA[y,x] = ImgFA[y x]

else begin ImgD"[y x] = Round( (lmgF'[y-l x- l]+lmyFA[y-l x]timgF"[)- 1 x+l]+

ImgFA[y ,x-l]+lingF''[y ,x]+lmgFA[y ,x+ l ]+ imgF"[y+l x-l]+lrngfA[y+l ,x]+lmgFA[y+l ,x+1])/9 if ImgD*[y,x] 63 then ImgDA[y x] = 63,

end end,

end Media *}

Procedure -Pdi-FMed I Var S: Selection;

Fuente,Destino. String, imagenF,lmagenD: Imagen, Tecla. byte: n: Byte; VJ GWindow,

Fuente:= S.sSelect(1 1 .'Imagen ? I ) ;

if Fuente e " then begin

begin

As i g n a M em ori a (I mag en F) ; Asig naMemoria(1 mag en Oj , Leelmagen(lmagenF, Fuente+'. ima'); MapealmagenjlmagenF, PAGINA-O): W,wlnit(l,Z,40,25, Falsej, W.wO pen ; W. wCursorOff I W.wWriteStrCo!or(' Filtra Media Aritmetica - TRABAJANDO...'. Amarillo). Media<lmagenF,lmagenD); Mapealmagen(lrnagenD,PAGINA-I); 'Jv. wClose ~

V isu a I iza Pa g I na (.l), n : = O, Repeat

Tecla:= LeeEspecial([ENT,ESC]); if Tecla = ENT then begin

VisualizaPagina(n); if (n = 1) then n:= O else n:= 1;

end; Until Tecla= ESC; VisualizaPagina(1); if Deseasalvar then begin

Destino:= TraeNombre + ' . h a ' : if Length(Destinoj =. 4 then

If Not Exis teA rc h (Des ti no) then

36

Page 36: MAGENES - 148.206.53.231

Es c r i be I mag en ( I mag en D , Des ti no)

it Con f I r m a c i o n {Des t I no j the ti else

Escribelmagen(1rnagenD Destino) end L I be ra Memo r I a(i nl a gen D) I

Li beraMemoriaíimagetiF), end,

end

begin end

-Pdi-Fi\/led *)

37

Page 37: MAGENES - 148.206.53.231

(,** OPERACIONES GEOMETRICAS ***I

...........................................................................

3 UANi.1 Lic en Computacion 7 r 2

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 {$ F+, O+}

Proyecto. Procesamiento Digital de lmagenes JPDI)

E' Rotacion de una imagen, Alrededor del centro del monitor. *}

Unit Pdi-Rota; Interface Procedure -Pdj-Rota: Implementation Uses Lib-Bas, Lib-Sel: Lib-Vent. Lib-Sec:

Type ArrlmgEsp = Array[-99 100, -159 1601of Byte TipolmgEsp = "ArrlmgEsp

Procedure CambiaOrigen(1mgFuente Imagen, Var imgAux TipolmgEsp), Var beg in

x y, Xaux, Yaux Integer,

Yaux = -99 For y = U to MAX-Y do begin

Xaux = -1 59 For x = O to MAX-X do beg I n

1mgAux"walix Xaux] = lingFuenteA[y, x] Xaux = Xaux + 1,

end Yaw = Yauy + 1

end end, y Cambiaorigen 3

Procedure Regresa@rrgen(Var ImgFuente Imagen, ImgAux TipoImgEspj, Var begin

end;

x, y, Xaux. Yaux. Integer;

Y = o, For Yaw = -99 to 100 do begin

X = O For Xaux = -1 59 to 160 do begin

lmgFuentenp X] = ImgAux"waux, Xaux], X = X + I ,

end Y = Y + 1

end

(" Regresaorigen 7

38

Page 38: MAGENES - 148.206.53.231

Procecic?re Rotacion(Var lmgF Imagen, TetaG Seal) Var x,y Xr Yr Integer,

TetaR Reai CosTeta, SinTeta Real Img4uxl lmgAux2 TioolmgEsp

Function A Integer beg in

end,

Function B Integer beg in

end, ? E 7

A = Trunc(r*CosTeta - '*Sinieta)

y A '3

E3 = TruncíPSinTeta + y*CosTetai

beg in New(lmgAux1 ) Newíl mgAux2) CambiaOrigenjlmgF, ImgAuxl), TetaR = TetaG*((2*?1)/360) CosTeta = CosFetaR) SinTeta = Sin(TetaR) For y = -99 to 100 do

For x = -159 to 160 do beg in

X r = A Yr= 3, if (Xr <= 160) And (Xr >= -159) And (Y'r <= I O O j And (Yr ;-= -G9j then

else ImgUu~2~[y,x] = ImgAuxl "[Vr Xr]

ImgAux2"[y XI = O end,

RegresaOrigenjlmgF, imgAux2j, Dispose(lmgAux1) Dicpose(lmgAux2)

end (" Rotücioii *: Function TraeAngulo(Var AnguloR Reai) Boolean, Var WTeta GWindow

AnguloS String, CODE Integer

TraeAngulo = FALSE if GetStrjWteta 1 1 ' Angulo 7 ' AngulaS 3 r-' ' O '9'1; then

Va I (Ang u los An g u I OR, 20DE) if CüüE <;. O then TraeAngulo = FALSE,

beg in

TraeAngulo = TRUE wTeta \Close

end C TraeAngulo 3

Procedure -Pd i-Rota, Var S: Selection.

39

Page 39: MAGENES - 148.206.53.231

Fuecte,Cest!no String Imagerif Imageri Tecla byte n Byte W GLVindow, Teta Real,

begin

end;

Fuente = SsSelectjI , I .'Imagen '?I);

if Fuente <> " then begin

Asigna M t m o r i a (I m age n F) ; Leeimagen(lmagenF,Fuente+'. itna'j, Mapealmagen(1magenF. PAGINA-0): if TraeAngulo(Teta) then begin

VV .wlnit(l,25,40,25, False); W.wOpen; W.wCursorGff; W.wWriteStrColorí' Rotacion - TRABAJANDO ' Amarillo). Rotacion jlmagenF,Tetaj; Ma pea I mag en (I mag en F PA G I N A- 1 ; W.wClose, VisuaiizaPagina(7): n:= O: Repeat

Tecla-= ieeEs~ec!aií[ENT,ESC]); if Tecla = ENT then begin

VisualizaPaginajn)' if (n = -I) then t i . = O else n:= 1 ;

end] Untii Tecla= ESC; VisuaiizaPagina(1 ji if Deseasalvar then begin

Destino.= TraeNombre + ' . h a ' , if Length(Destin0) > 4 then

if Not ExisteArch(Destino'r then

else Escribeimagen(lmagenF. Destino)

if Confirmaciul ,$estino) then Escribelmagen ( I magen f. Desti no)

end: L i be ra Me m v r i a (I mag en Ff :

i31d; ena:

(* -Pdi-Rota *} begin end.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *l.

C UAM-I Lic. en Lomputacion 3 c* *I

J

Proyecto: Procesamiento Digital de lmagenes (PDI) 3

40

Page 40: MAGENES - 148.206.53.231

r Traslacio;. de vna lrnagen 7 (c****+*+'+**tt+******+~++**+**+***+++*+***~*~****++~***tt*+** +? J

{9F+ o+> U nit Pd i- Tras Interface Pruced i i re -Pd i-Tras, i rn pleme ntation Uses Lib-Bas Lib-Sei Lib-Vent Lib-Sec

Procedure Traslacion(1mgF Imagen Var lmgD Imagen Xo Yo Word) Var x,y Word,

XrYr Longlnt

Function A Longlilt begin

end, ? A ? Function B Longlnt beg i t i

end,

A = x - Xo,

B = y - Y O

í? B *I begin

for y:= O to WlAX-Y do tor x:= O to MAX--X do beg in

Xr:= A, Yr.= 6, if (Xr =.= O} And (Xr é- MAX-X} Arid jYr =.= O) And Tiir <= MAX-V, tneri

else I m g DA [y, x] : = I m g F A r ~ Xr]

ImgDA[y,x]:= O; end;

end; (* Traslacion *)

Var

begin

Procedure -Pd ¡-Tras, S. Selection. Fuente,Destino String ImagenF ImagenD Imagen n Byte WJ GWicdovv Tecla Byte FactorEnX FactorEnY Real XoYo Word

Fuente = S sSelect(1 1 'Imagen 77,

if Fuente <> then begin

Asigna M e mo r i a (I m age n F) ,4 s I g n a Me mor I a ( I m age n D) , Leelmagen(lmagenF,Fuetite+' irna'), h'lapealmagen(1magenF PAGINA-O), if TraeOrigenfXo Yo) then

41

Page 41: MAGENES - 148.206.53.231

begin W.~lnitjl,25,40,25,False), W.wOpen; W .wCursorOff; W wWriteStrColor(' Traslacion - TRABAJANDO. Traslacion(lmagenF,ImagenD: Xo, Yo); Mapeal magenílmagenD: PAGINA-1 1, W.wClose, VisualizaPaginaíI): n:= O; Repeat

Amarillo);

Tecla:= LeeEspecial([ENT,ESCI); if Tecla = ENT then beg in

VisualizaPagina(n); if (n = 1) then n.= O else n:= I ;

end; Until Tecla= ESC, VisualizaPagina(1): if Deseasalvar then begin

Destino.= TraeNombre + ' . h a ' : it Length(Destin0) 4 then

If Not ExsteArchjDestino) then

else Escribe!magen(lmagenD, Destino!

if Confirmacion(Destinoj then Escribelmagen(lmagenD. üestino).

end end, L I be ra M e m o r i a ( I mag en D) Li berah/lemoria(lmagenF)

end. end

begin end

-Pdi-Tras *>

Proyecto Procesamiento Digital de lmagenes (?DI; 0) {* UAM-I i i c en Computacion *> r 3

*I Reflexion Sobre una Linea Horizontal rii*,**C*****tt*****~~**********~******~**********m~******** rn J {$F+ O+) Un it Pd i-R ef H , Interface Procedwe -Pd i-RefH I rri plemen tation Uses Lib-bas Lib-Se1 Lib-Vent Lib-Sec

ProcedEre ReflextonjirngF Imagen, Var Irngr) Imagen c Word), Var x,y Word,

Xr Yr Longltit,

42

Page 42: MAGENES - 148.206.53.231

Function 4% Lonc;ftit begin

end

Function €3 Lcnglnt, begin

end (* B *)

A = x

r A 3

B = c - ~ ,

begin for y = O to MAX-Y do

for x = O to MAX-X do begin

Xr = A Yr = B, if (Xr =-= O) And (Xr <= MAX-X) And (Yr >= O) And (Yr <= MAX-Y) then

else imgDA[y.x] = ImgFAIYr Xr]

IinyDA[y,x] = O end,

end, f* Reflexion *}

Functioti TraeLineaDeReflexion(Var c Word) Boolean, Var Wc GWindow,

Sc String CODE Integer,

TraeLineaDeReflexion = FALSE if GetStr(VVc,i 1 'Linea Horiz de Reflexion 7 ' Sc 3 ['O' '9'1) then

Wc wClose, Val(Sc, c , CODE), if CODE e O then TraeLineaDeReflexion = FALSE

beg in

TraeLineaDeReflexion = TRUE.

end TweLineaDeReflexion *>

Procedure -Pdi--Ref H I Var S: Selection.

Fuente,Destino: String: I m age t i F , I m age n D : ! mag e n ; n: Byte; W: GWindow: Tecla: Byte; c. Word.

Fuente.= S.sSelect(l .I ,'Imagen ? I ) ,

if Fuente .c=. I' then begin

begin

As ic] n a M e m o r i a ( I mag en F) AsignaMemoriaíl tnageni)), Leeimagen(imagenF,Fuente+'.itna'i; Mapealmagen(lmaaenF. PAGINA-O);

43

Page 43: MAGENES - 148.206.53.231

if TraeLinoaDeReflexronO then begirt

W. wI nití1 : 25,4U,25, False); W .wOpen. W wCursorOff; ?41. ?r/Vl'r i test rC o! o r i' Ref 1 ex¡ on Horizon ta I - TR A BAJAN DO ' , Am a r! I ! c?) ; Reflexion(lmagenF,ItnagenD:c)3 MapealmagenjlmagenD,PAí;INH_I j. W .wClose. \/iscia!izaPagin?(l) n.= O: Repest

Tecla.- LeeEspecial([ENT,ESC]), it Tecla = ENT then begin

Visua!izaPagina<n) if in = 1) then n:= c! else n.= 1,

end; Until Tecla= ESCi VisualizaPagina(1): if Deseasalvar then begin

Destino:= TraeNombre + '.lma', if Length(Destino) =. 4 then

If Not EsisteArch(Destino) then

else Escribeimagen(imagei70: Destino)

if Confirmacion(Destino) then Escribelmagen(1magenD Destino).

end; end; LiberaMernoria(1magenD); LiberaMemoria(1magenF): end:

end;

begin end.

P I - Fdi-RefH 7

i*******************4******r*************~*********~*4***~~**i+4 +?

f' UAM-I Lic en Computacion *} 3 (*

I r Proyecto Procesamiento Digital de Imagenes (PDI) *}

*' Reflexion Sobre una Linea Vertical J

1 I {SF+ O+) I J nit Pdi-RefV Iri+erfacs Proced ~i re -Pd i-RefV, Implementation Uses Lib-Bas, Lib--Sel, Lib-Vent Lib-Sec,

y l * * * * * * * * * * f * * i * * * * * * * * * i * * * T * * r * ~ * ~ ~ * * ~ . ~ ~ * ~ ~ ~ * ~ ~ ~ ~ , ~ * 41

Procedure Reflexioti<itnyF ltnagen Va: 1mgD Imagen z Word), Vai x,y Word

Xr Yr Longlnt

44

Page 44: MAGENES - 148.206.53.231

FLirtctior: A Longln!, bey i n

end

Function B Lotiglnt beg in

B = y end,

A = c - x

c* A *I

I B 3 begin

for y = O to MAX-Y do for x = O to M4X-X do begir;

Xr = A, Y r = B if (Xr >= O) And jXr <:= MAX-X) And ;Vi >= O) And (Yr -<= MAX-Y) then

ImgD"[y,x] = ImgFS'pfr Xr]

ImgD"[y,x] = O. end,

end Reflexion *}

Function TraeLineaDeReflexion(Var c Word) Boolean Var Wc GWindow

Sc String, CODE integer,

TraeLineaDeReflexion = FALSE if GetStr(Wc 1 1 'Linea Vert de Reflexion 7 ' Sc 3 r5' '9'1)

we WCI ose,

beg in

then TraeLineaDeRefleuion = TRUE

Val@, c CODEJ, if CODE <> U then TraeLineaDeReflexiori = FALSE, end r* TraeLineaDeRefleuion 7

Pi ocedure -Pdi-RefV Var S Selection

Fuente Destino String ImagenF ImagenD Imagen n 6yt5, W GWindow, Tecla Byte c Word

Fuente = S sSelectj1 1 'Imagen 7'1, if Fuente c> " then beg in

begin

Asigna Memoria (imagen F) As i g n a M e mo r I a (1 m age n D) , Leelmageti~ltnagenF Fuente+' ima') bla pea I magen ( I rnagen F PAC; IN A-O) it rraeLineaDeReflexionO then

45

Page 45: MAGENES - 148.206.53.231

begin W. wln ¡!(I! 2 5 , 4 0 3 , Fa ice); 'Ai. w0 pe n : W. wCursorOff; W.wWriteStrColor(' Reflexion Vertical - TRABAJANDO . . ' Amarillo)- Reflexion(lmagenF, ImagenD,c); MapeaimagenjlmagenD,PAGINA-I j: W.wClose, VisualizaPagina(1); n:= O. Repeat

Tecla.= LeeEsFec;ial([ENT,ESCI)? if Tecla = ENT then begin

VisualizaPaginajn); if (n = 1) then ~i.= U else n'= 1;

end; Until Tecla= ESC: VisualizaPagina(1); if Deseasalvar then begin

Destino.= TraeNombre + '.lma'; if Length(Destin0) > 4 then

If Not ExisteArch(Destinoj then

else Escribelmagen(lmagen0. Destino)

if ConfirrnacioníDestino) then Escribelmagen(lmagenD.Destinoj;

end; end, L I be ra M e m o r i a (I mag en D) , LiberaMemoria(lmagenF)i end,

end;

begin end.

-Pdi-RefV *)

46

Page 46: MAGENES - 148.206.53.231

1 (*=***********R********************************~*****~***=**~ *

Proyecto Procesamierito Digital de imagenec (Poli i. ?; l iAfi?i I L i C e? coQlputc;ciPr- *¡

r I

{' Cambio en el Contraste de una Iniayeri +I .............................................................. 'i

*?

I

{$F+ O+? Unit Fdi-Cont Interface Procedure -Pdi-Cont, Implementation Uses Lib-6as Lib-Sei Lib-Vent Lib-Sec

Procedure ContrasteílmgF Imagen Var lmgD Imagen Factor Real), Var x y Word

dxdy Word Aux Longlnt,

for y = 0 to lViAX-Y do for x = O to MAX-Y do begin

begin

Aux = Round{IrngF*[y,x] * Factor) if Aux <= 63 tnen

else ImgDA[y,x] = BvtejAux)

ImgDA[y,x] = 63, end;

end; Contraste '3

Function TraeFactor(Var f: Real). Boolean; Var Sf: String;

Wf: Gwindow; CODE. Integer.

TraeFactor:= FALSE, Sf:= ' I ; if GetStr(VVf,l ,I , ' Factor de Contraste ? '~Sf ,3 ,~. ' : 'O ' . . '~ ' ] j then ?raeFactor:= TRUE, Wf. Wclose: Val(Sf,f:C@IS)E): if CODE

begin

Other TraeFactor.= FALSE; end,

TraeFactor *}

Procedure -Pdi-Cont Var S Selection

Fuente Destino String ImagenF,lmagenD imagen Tecla byte n Byte W GLVi ndow fcont Real

beg 1 n

47

Page 47: MAGENES - 148.206.53.231

Fuente = 3 sSclect[i I 'ImaGen ,f F.m-i:e :: " then beg i i i

As I g na Memoria (I mag en F) As i g n a Me m o ri a ( I mag en D) Leelmagen(lmagenF,Fuwte+' ima') MapeáltnayenílmagenF FAGINA-Oj if l~raefdctor(tcontj then begin

W wlnitil 25 40 25 False) '$4 wOpen W wCursorOff, L/v wWriteCtrColorí Contraste - TRAEAJANDO I , Amarillo) Contraste(1magenF ImagenD fcont) 1\/1,7uealtnagenílmager~~ P,4GIr\i,4-1) w \IvClose, VisualizaPayina(l), n = O, Repeat

Tecla = LeeEspecial([ENT ESC]), if Tecla = ENT then begiii

VisualizaPagina(nj, if (n = 1) then n = O else n = 1

end Until Tecla= ESC, L isual izaPagina(1) if Deseasalvar then beg in

Destino TraeNcmbre f ' Ima' if Length(Destin0) 4 then If Not ExisteArch(Destinoj then

else Esc ri be I mag en ( I mag en D Dest I no)

if Confirmaeion(Destino) then Escribelmagen(lmageriD, Destino)

end end iiberah4emoria (lmagenü) L I be ra ivi e mo r I a { I m age n F)

end, end,

beg 1 n ei1d

-Pdi-Cont 3

7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

UAivl-I Lic en Computacion I c" *I

7 1

{$ F+ ,O+} U nit Pdi-Esc, Interface

Proyecto Procesamiento Digital de Imagenes (PDI) *} *?

Cambio en la e.scala de los nivsles de gris r***************************************~********************* * 1.

48

Page 48: MAGENES - 148.206.53.231

Prccediire -Pdi-Esc I rn ple rne n t a t m &es Lio-bas ii-3eI Lib-Veiit, Lib-Sec

Procedure Corrmtento(lmgF Imagen, Var lrngü Imagen, Corrirntento Integer) Var x y Word

dx dy Word AUX Longlnt

for y = O to h4AX-Y do for x 2 U to MAX-X do begin

beg 1 n

Aux = ImgF*[y x] + Corrimiento if Aux .== 63 then begin

if Aux < O then

else ImgDA[y,x] = O

ImgDA[y x] = Byte(Auxji end else

end. end; y Corrimiento J

ImgDA[y,x]:= 63:

Function TraeCorrirniento(Var C: Integer): Boolean; Var Sc. String;

Wc. Gwindowr CODE: Integer;

TraeCorrimiento.= FALSE: Sc:= ' I ; if GetStr(Wc,l ,I Corrimiento 7 ',Sc,3>r-','O' .'9']) then

Wc.Wclose; Val(Sc.c.CODE); if CODE <=- 0 then

begin

TraeCorrimiento:= TRUE,

TraeCorrimiento:= F.4LCE; end; (* TraeCorrimieiito *>

Procedure -Pdi-Esc Var S Selection

Fuente,Destino String, ImagenF,lmagenD Imagen, Tecla byte, n Byte W GWindow, Corr Integer,

Fut.qte = S sCeiectj1 ,I 'imagen 7') if Fi:ente ,-: " then begin

begin

As i g n a M e m or I a (i rn age n F) , As i g na Memo ria ( I mag e n Di

49

Page 49: MAGENES - 148.206.53.231

Leelmagen(lrnagerF Fuente+' ima') i \ i lapealma~en~l rnagei lF,PAGl~~~~~), if T raecorrimien to(Corr) then begin

W wlvit(l,25 40 25 False) 'vif sví?pen VV wCursorOff, W wWnteStrCoiorj' Cambio en la Escala - TR Corrimiento(1magenF ImagenD corrl MapealmageníImagenD P4GIN4-1j w wClose VicualizaPagiriajl) n = O Repeat

Tecla = LeeEspecial([ENT ESC]) if Tecla = ENT then begin

VisualizaPagi na(n) if in = I ) then n = 9 else n = 1

end Until Tecla= ESC VisualizaPaginajI j if Deseasalvar then begin

Destino = TraeNombre + h a ' if Length(Dectino) 4 then

BAJ JDO ' Amaiillo)

If Not ExisteArch(Destino) then

else Escribelmagen(lmageni3,Destino)

if Confirmacion(Destin0) then Escribe1 tnagen(imagen5, Destino)

end, end, Li beraMemoria(1rnagenDj' LiberaMemoria(lmagenF),

end end, (* -Pdi-Esc *} begin end

C*****t*********C*****t*ttt*************~********************************** u! 1 f" Proyecto Procesamiento Digital de lmagenes (PDI) *}

UAhI-I Lic en Computacion 3 r *I (* Cornplementacion (Inversion) de una Imagen *! ........................................................................... i

($F+ O+' Unit Pdi-Corrip Interface Procedure -Pdi-Comp Implementation Lises Lib-Bas, Lib-Vent Lib-Se1 Lib-Sec

Procedure ComplementacionjlmgF Imagen. Var lmgD imaqen)

50

Page 50: MAGENES - 148.206.53.231

Var XJ: WOK; begin

for y.= O to MAA-Y do for x:= O to MAX-X do begin

Case ImgF"[y,x] of O ImgD"[y,x]:= 63, I ..31 . lmgDA[y;x].= 32 + (32 - IingF"[y,x]), 32 : ImgDA[y.x]:= 32; 33 .62 : ImgDn[y,x]:= 32 - (ImgFA[y.x] - 32): 63 : ImgDA[y:x]'= O;

end; end,

end; Completner?tacion *>

Procedure -Pdi-Comp, Var S Selection,

Fuente Destino String ImagenF ImagenD imagen Tecla byte,

W GWindow,

Fuente = S sSeloct(1 1 'Imagen '') if Fgente c~ 'I then beg i ti

n w e ,

begin

AsignaMemoria(lmagenF), Asigna Memoria (ImagenD) Leelmagen(1magenF Fuente+' irva'), MapealmayenjltnageiiF PAGINA-O], W wlnit(l,25 40,25 False) W wOpen W vvCiirsorOfi L11 wWriteStrColor(' Complemerita - TRABAJANDO ' Avarilio), Compiementacion~imagenF,imagenüj Mapealmagen(lmagenD,PAGINA-I), W ?"lose VisualizaPagina(7) n = O Repeat

Tecia = LeeEspecial([ENT ESC]), if Tecla = EhT then begin

VisualizaPaginafn) if (n = 1) then n = O else n = 1,

end, Until Tecla= ESC Visual iza Pag ina (I) if Deseasalbar then begin

Destino = TraeNombre + ' ima' if LengthíDestino) > 4 then

If Not ExisteArch(Destino) then

else Escribelmagen(lmagenD,Cectinoj

if ConfirmacionjDrstino) then

51

Page 51: MAGENES - 148.206.53.231

Escribe!ma~er(f..7a3..nD Destino) end L i be ra rvl e m o ria (I m age n Gj Li befa Memoria (I mag en F) ,

end

-Pd-Comp 3 end

beg t n end

Procedure MaxMinPix(lmg imagen Var Min I\Jla:: Byte) Vai x y integer beg in

Max = O Min = 255 for y = O t G MAX-Y do

for x = O to MAX-X do beg i n

if Img"[y x] = Max then Max = ImgA[v x] else

if ImcP[y x] .c hilin t h e n ' ' = img^[y,x] L, IU

- 4

{* MaxMinPix 7

Procedure GistribuyejlmgF Imagen Var ImgD Imager; MitG MaxG Byte) Var x,y integer,

begin Min Max Byte,

MaxMinPix(imgF Min Max) for y = O to M A - Y do

for x = U to MAX-X do imgDA[y x] = ((MaxG- MinG)*(lmgF*[y XI-Min)) DiVíMax - Min) + minG

erid f* Distribuye *I

Function TraeValoresiVar MinG MaxG Byte) Boolean

52

Page 52: MAGENES - 148.206.53.231

V a

begin

end

TraeValores = FALSE SminG = " SmaxG = " if GetStrtWminG 1 1 'Miniino Gris 7 ' SminG,3 ['O' '9'1) then beg In

' SmaxG 3 YO' ci'j) then if GetStr(WmaxG I 4 'Maxim0 Gris

LSJmirG wClcce '&ri iáxG wZlose,

Traevalores = TRCiE

end else

t'al(Srnlv3, r i n C Lt"lIIE; if CODE := O then iraeVaiores = FALSE ValiCmaxG maxG, CODE), if CODE e O then TraeValores = FALSE,

'\Iv I-P I t? G \4/c /ose

Traevalores 7

Procedure -Pdi-Dist 'dar S Selection

Fuente Destino Stricg lrnagenf IrnagenD lrnagefi Tec I a b yie, n Byte W GWindow MinGrrs MaxGris Byte

Fuente = S sSelectj1 I 'Itnayen 7'1, if Fuente .=>- '' then beg in

beg in

Acignal\/lemor,a(Image~F~ AsignaMernor iajltnagenD) Leeimagen(1magenF Fuente+ ima') MapealmagenflmagenF PAGINA-@) if TraeValoresíMinGris MaxGris) then begin

W wlnit(1 15 40,25 False), 1/v wc'pen, W wCiirsorOff W wWriteStrSolor(' Distribuciorl de bJtL'eles - TRABAJANDO ' Amarille) Dist: i~uyeílmagetiF,l tnagenD,Mi~~ris MaxGris), Mapealmagen{lmagenD PAGINA-1 ) > W wClose ViscializaPaginajI) n = O Re peat

Tecia = LeeEspecial([ENT ESC]) if Tecla = ENT t h e n begin

Vis u a I iza Pag i n a (n) if (n = I) then n = 0 else n = 1

end, Until Tecla= ESC

53

Page 53: MAGENES - 148.206.53.231

VisualizaPagir?ajlj if Deseasalvar then beg in

DPstino = TraeNombre + ' tma' if Length(@estino) : 4 then

If Not ExisteArch(Destrno) then EscnbelinagenjlinayenD, Destino;

else if C'onfirmacion(Destino) then

Escribelmagen jlmagenD Destino) end,

end, Li beraMemoria(lmagenü), Li beraMemoria(1magenF)

end, end,

begin end

-Pdi-Dist 7

54

Page 54: MAGENES - 148.206.53.231

1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

Proyecto: Procesamiento Digital de lmagenes (PDI) 7 Y tJAh4-l Lic en Compcitacion *i r 7 Y Dilatacion del gradiente de una imagen. 3 t 1. {S F+. O+) Unit Pdi-Di!a: Interface Procedure -Pd i-D i la; Implementation Uses Lib-Bas, Lib-Sel. Lib-Vent. Lib-Sec, Lib-Menu; Type TipoRejilla = Arrayíl..5. 1 ..5] of integer;

I-****n*"*f***f***C*****fx*r******n***x***~****************~* Y

Const R1 TipoRejiila = (

R2: TipoRejilla = (

R3 TipoRejitla = (

R4 TipoRejilla = (

R5: TipoRejilla = (

R6. TipoRejilla = (

R i TipoRejilla = {

55

Page 55: MAGENES - 148.206.53.231

Function SeleccionaRejilla Byte Var W GWindow

O byte

Function TraeSeleccion: byte; Var nR, Aux, Tecla: Byte: begin

nR:= 1 W. wGo~oXY j4,2j: \IV.wWriteStrColor('-j', Rojo);

w wW ri test rCo I or ( j . . I , fi oj o) ; Repeat

Aux.= nR; Tecla:= LeeEspecial([F-IZQ, F-DER, ESC. ENJ): Case Tecla Of

F-IZQ : if nR > I t h w Dec(nR) else nR:- 9,

F-DER : if nR < 9 then Inc(nR) else nR:= 1 '

ES- ' begin

Numero de Rejilla 3

w.wGotoXY(7 2)

TraeCeleccion:= O; Exit:

end; end: If Tecla e> ENT then begin

Case Hux oí I : begin

W.wGotoXY(4.2):~ wWriteStrColnr(' '.Rojo); W w2 otoXY (7 : 2) ; w . WW r i te S trCo I o r (' i Rojo) ;

end; 2 : begin

W . wG otoXY (1 6 2) ; \iv . wVV ri test rCo I o r ( ' Rojo) : LV wGotoXY(l9,2):LV wWriteStrColorj' ' .ROJO);

end; 3 beg I tl

VV. wGotoXY (28: 2); W w'WriteStrColorj' Rojo), W.wGotoXY(31.2):W wWriteStrColor(' ',ROJO).

56

Page 56: MAGENES - 148.206.53.231

4

5

6

7

8

9

end, Case nR of

I

4

5

6

7

8

end kegin

V\/ vvGotoXY (4 9) w WWriteStrColorJ' ROJO) W wGotoXY(7 91 w wWriteStrColor( Rojo)

end begin

W wGotoXY{?G 9) \N vvWriteStrColorí' ' ROJO)

VV wGotoXY(19,9),W wVVriteStrColorj' ' Rojo), end

beg in W ,vC;otaXY{28,9),?'V \n/V?';itGtrColorj' ' Rojo: V\i wGotohY;sl ,Y) 'vV vAWriteStiColor(' ' Rojo)

end, beg in

W wGotoXY(4 16) \A/ wtWriteStrCcilorí' Rojo) wSotoXY(7,: 61, w wWriteStrColor(' ',Rojo/

end, begin

W wGotoXY(l6 16) W wWriteStrColor(' Rojo) W wGotoXY(í9 16) W wWriteStrCoIor( ' Rojo)

end begin

W wGotoXY(28,lfi) W wWriteStrColorj' ,ROJO), W wGotoXY(31 16) W wWriteStrColor(' ROJO)

end

beg in W wGotoXY(4 2 ) ! ~ wWriteStrColor('-(' ROJO) \SJ wGotoXY(7 2),w wWriteStrColor(')-' ROJO)

end begin

W wGotoXY(l6 2),w wWriteStrColor('-(' Rojo) w wGotoXY(19 2!,w wWriteStrColor('}-' ROJO)

end, begin

W wGotoXY(28,2),LZI wWriteStrColor('-(' ROJO) w wGotoXY(31,2) w wWriteStrColor()-' Rojo)

end begin

W wGotoXY(4 9), w wWriteStrCo1orj'-(' Rojo) w wGotoXY (7,9), w wWriteStrColor(')-', Rojo),

end begin

191 wGotoXY(1 U 9),W wWriteStrC;doí('-(', Rojo; w wGotoXY(19,9) w wVVriteStrZo1ort')- ,Rojo),

end begin

VV wGotoXY(28,9) ,W wVVriteCtrColor('-(' ROJO) w wGotoXY(3l 9) v ~ i wVVriteStrColorJ') ',Rojo)

end begin

W wGotoXY(4 1&),w wWriteStrColor('-j' Rojo) w wGotoXY(? 16) w wVJriteStrColor(')-' Rajo)

end begin

W wGotoXY(l6 ? U ) W wWriteStrColor('-(' ROJO)

57

Page 57: MAGENES - 148.206.53.231

\Y \G.otoXY(? 9 1 E) \Y/ wWriteStrColor:') ' Rolo; end

9 beg I I1 Vd wGotoXY(28 16) W wVVriteStrColori'-(' Rojo) w wGotoXY(31 16) w wWrtteStrColor(')-' Rojo)

end end

end Until Tecta = ENT TraeCeleccion = nR

end

1raeSeieccion *>

With vv dc begin

begin

wlnitjl ,I ,37,24,TRUE); wOpen; wCursorOff I wGotoXY(1:2): wWriteStrColorj' ?'.Amarillo). wGotoxy(l,3);wWriteStrColor(' I 1 I O 0;MForeGroünd); wí;otoXY(1,4j,wWriteStrColorj' U U O U O',MForeGround); wGotoxy(1 ,fjj;wWriteStrColor(' O O O O O'.MForeGround); wGotoxy(1 .G);wWriteStrColor(' O O O O O',MForeGround): wGotoxy(1 ,T)iwWriteStrColor(' O O O O O',MForeGround): wGotoXY(13,2);wWriteStrColorj' 2',Amarillo); wGotoxy(l3,3);wWriteStrColor(' 1 1 I 1 l',MForeGroundj. wGotoXY(13,4);wWriteCtrColor(' O O O O O'.MForeGroundj. wGotoxy(l3.5);wWriteStrColor(' O O O O O'tMFareGround)i ~~~.;Gotox.y(13,5),L?/'WriteStrCoIorj' O O O O O'.MForeGround); wGotoxy<l L2,7j,\ri'vZiriteStrColcrj' O O O O O',MForeGrcund), wGotoXY(L5,2j,wWriteStrColor(' 3',Atnarilis), wGotoxyí25.3)iwWriteStrColori' 1 O O O O',MForeGround): wGotoXY(25,4):wWriteStrColorj' 1 O O O O'. PdForeGrociodj: wGotoxy;25, S)~~~~WrireStiCoIor(' 1 O V O O', MFoieC round); wOotoxyj25,Gj.wL'tiriteStrZoiuij' U O O O O'.hiiForeGrourid), wGotoxy(L5, i).wVVriteStrCoiort' O 0 O O 0'~ivlForeGround). wGotoXYI WG otsx y i I v:G2toXY( wGotoxyi I wGotoxy( 1 wGotoxy( 1 WG otoXY (

9) wViJriteStrColor(' 4' Amarillo) 1 O) wVVriteStrColorj' I O O O O' j\iiFoW3ou ndj ,I 1) VvWriteStrSolor\' 1 O O O G',MForeC;roiinci) I ?I,w\r\iriteStrCuiorí' I O U 3 O' ivtForeGrouiid), 13),w\/VriteStrColor(' 1 O U O O',MForeGround) 14) wWriteStrColorí' 1 O O O ci' MForeGround! 3 9) i+NriteStrColcri' 5' 4marillo)

\NGGtGXy<? 3,1@j,;y\jllriteStrColorí' I i 1 O @',MForeGroundj wGotoX'Í(13,I l),wWri:eStrSolor( 1 I I O O' MForeGroundj wGotoxyjl3 I Z),wWriteStrCoiori' 1 1 1 U ü',MForeGround) wGcitoxy(l3 13) wWriteStrColor(' O O O O O' MForeGround) wGotoxy(l3 14) wW:iteStrColor(' O O O O O' MForeGrcund) wGotoXY (25,9) , wl'l'riteStrlolo rj' wGotoxy(25 ?O) wWriteStrColorc 1 1 1 I 1' MForeGroLindj wGotoXY(25 1 l),wWriteStrColor(' 1 1 ? 1 1 ' MForeGround) \niGOtOXV(2!j 12) wWriteStrColsr(' I 1 1 1 1' MForeGround) wGotoxy(25 13) LvWriteStrColorC O O O O O' MForeGround) wGotoxy(25 14) wWriteStrCoior(' O O O G O' MForeGround; wGotoXY(i,16) wVVr iteStrCoiorj' wGotoxy(1 17) wWriteStrColorf' I I 1 I) O' MForeGround)

6' Arriar1 I io),

7' Ama1 1 1 1 0 )

58

Page 58: MAGENES - 148.206.53.231

wGdoYY(1 18) wVJriteStrColorj' I 1 c) Q' VCnreGroundj wGotoxyil 19; , dJVriteStrColorj' 1 1 1 O O,klForeGrcui?dj, wGotoxyíl,2O) wWriteStrColorj 1 1 1 6 U ii/iForei;rounal wGotoxyf1 SI) wWriteStrColorí' 1 1 1 O U MForeSround) wGotoXY(13 16) wVJriteStrCoior(' 8' 4marillo) wGotouyji 3,771 ,wWriteStrColorj' 1 1 I 1 1' lLilForeSrounrfj, wGotoXY(13 18j,wVVriteStrC:olorj' 1 1 1 1 I',MForeGrotcnJj vvYí;otoxy(l3 19) wWriteStrCoioi( 1 1 I 1 1 i\/lforeGrouridj, wGotoxy(l3 20) ,wWriteStrColor( 1 1 1 I I ' MFareGround) ihiGotox~~13,Y) \NVVriteStrColori' 1 I 1 1 1' MForeGround) :V&tOXY(25 16) ,wLVriteStrColor(' 9' Amarillo) wGcitoxy<25,17) ,wWriteStrColort' U 1 i 1 O',fv'lForeGrounci), wGotoXY(25, is> wWriteStrColorr 1 1 I I I' MForeGround) wGotoxvj25 19) wWriteStrColor(' I 1 1 I I ' MForeGround) wGotoq(25 20) wWriteStrColorf 1 I I 1 I ' MForeGroiJnd) wGotoxyj25,Zl) ,wWriteStrColor(' O 1 1 1 O',MForeGround)

end, O = TraeSeleccion, W wClose, SelPccionaRe!illa = O

end, i* SeieccionaRejilla *}

Procedure -Pdi-Dila, Var S Selection,

Fuente Destino String ImagenF,lmagenD lmagen Tecla byte, n Byte W GWindow, nRejilla Byte

4

Procedure Inicial izaíVaí I my I mag en) Var x y Ward begin

for y = O to MAX-Y do for x = O to M a x X do

Irng"[y x] = O end, (* Inicializa 3

Procedure SLimaDeMrnkowski(lrngF Imagen, Var ImgD lmagsn, Re, TipoRejilla,

Var begin

Re] M axA, Rej M ax'/ b'v o r d) , DeltaCentroRotX, DeltaCentroRotY m n, I, I , x, y Integer

DeltaCentroRotX = (RejMaxX div 2) DeltaCentroRotY = (RejMaxY div 2), I t i icial iza (I tng Di, for y = DeltaCentroRotY to MAX-Y-DeltaCentroRotY do

if IrngFn[y,r] c). O then begiri

for x = DeltaCentroRotX to MAX-X-DeltaCentraRotX do

rn = y - DeltaCentroRotY for 1 = I to RejMaxY do

59

Page 59: MAGENES - 148.206.53.231

begin n = x - DeltaSentroRot)! for i = 1 to RejfVlaxX do begin

if (RejD,i] = 1) And (IrngF"[y x] =. lmgDh[m n]) then

incín) ImgD"[m,n] = imsFA[y,x],

end, Inc(m).

end end

end, SumaDeMinkowski *}

Principal *} begin

Fuente:= S.sSelect(? ,I ,'imagen ?'>; if Fuente <' I' then begin

As ig t i a Me m o r i a (Image t i F) ; Leelmagen(lmagenF,Fuente+'.ima'), Mapeaimagen(imagenF, PAGINA-O), nRejilla:= SeleccionaRejiila. if nRejiila <> O then begin

AsignaMemoria (ImagenD); W.wlnit( 1,2540.25, False); W. w 0 pen; W . wC ii rsorOff W.wWriteStrColor( Dilatacion - TRABAJANDO.. ', Amarillo); Case nRejiila Of

1 2 3 4 5 6 7 e 9

: SumaDeMinkowskijlmagenF. ImagenD. R I . 1. 31. : SumaDeMinkowski(ImagenF, IrnagenD, R2, 1, 51, ' SutnaDeMinkowsKi(lmagenF, ImagenD, R2, 3 , 1); . SumaDeMinkowskijlmagenF, ImagenD, R4, 5, 1). : SumaDeMinkowski(1magenF: ImagenD, RS, 3,3 j . : SumaDeMinkowski(lmagenF, ImagenD. R6. 3. 5), : SutnaDeMinkowski[!magenF. Imagen@. R7, 5. 3)- : SumaDeh/linkowski(lmagenf, ImagenD, R8, 5, 51, SumaDei\/iinkowski(lmagenF, ImagenD, R9 5: 5),

end; Ma pea I mag en ( I mag en DI P AG I N A- 1 1 : W wC I ose : VisualizaPagitia(l), t i : = O ; Repeat

Tecla:= LeeEspecial([ENT, E X ] ) : if Tecla = ENT then begin

VisualizaPagina(n), if (n = 1 j then n . = O else n:= I:

end: Until Tecla= ESC; VisualizaPagina(1): if Deseasalvar then begin

GO

Page 60: MAGENES - 148.206.53.231

Drstinc = Trar-Nombre + ' h a ' if iength(Dest!no) ;- 4 then

If Not ExisteArch(Destino/ then

else Escribelmagen( ImagenD Destino)

if Confirmacion(Dest1no) then EscribelmagenjltnagenD Destino),

end LiberaMemona(1magenD)

end L i be ra IL1 e m u r 1 a (Imagen F j

end end, (* -Pdi-Dila *} begin end

7 r**************************t********************************** (* Proyecto Procesamiento Digital de lmagenes (PDI) *;

'3 r UAM-I Lic en Computacion

i* *> *> (" Erosion del gradiente de una imagen > . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

{SF+ O+> Unit Pdi-Eros, Interface Procedure -Pdi-Eros Implementation Uses Lib-Bas Lib-Sei, Lib-Vent, Lib-Sec, Lib-Menu, iyw TipoRejilla = Array[l Const R1 TipoRejtlla = í

R2 TipoRejilla = i

R3: TipoRejilla = (

R4. TipoRejilla = (

5, 1 -51 of Integer,

(I, 1 ?,I, I ) ío, o, o o O) (0 0, O, O, Uj io, o, o o O) (O o o o O))

( I o o, o 0) (I o, o o O) (1 o o o 0) (O, o, o o O) io o o, o, O)) ,

61

Page 61: MAGENES - 148.206.53.231

R5 T ¡ p R ~ j i ! l : ~ (l. ? : o; U) (1; '1; 1; o: O); (I. 1, '1. O: Oj . (O. o. O: o. O). ío. o. o. o. O)):

R6 TipoRejilla = ( {q, 1 1, 1 1) (1 1, 1 1 '1 (I 1 1 I, 1 ) {O o o 13 O) (0 O, 9, c q,

R8 TipoRejilla = { (1 1 1 1 1) { I , 1 1 I I) {I 1, I, 1 1) (1, 1 1 I 1) (1 1 1 1 l ) j ,

R9 TipoRejillu. = ( (O, I , I 1 O) (1, 1 1, 1 I) ('I ? , ? 1,7) , (1, I 1 1 1) (0 1 1 1 O ) ) ,

Function SeleccionaReylla Byte Var W GWindow

o bytte,

Function TraeSeleccion bvte Var PR Aux Tecla Byte begin

nR = 1,

W wWriteStrColor('-í', Rojo) w wGotoXY (7,2) w wWriteS:rCo!cv(')-', Rojoj, Repeat

t<Limero de Reylla 7 VV' wGotoXY (4,2),

Aux= nR Tecla LeeEspecial([F-lZ'Q F-DER ESC ENTJi Case Tecla Of

F-IZQ if nR : I then Dec(ilR)

F-DER if nR 9 then Inc(nR)

ESC begin

else nR = 9

else nR = 1

TraeSeleccion = O Exit

end

62

Page 62: MAGENES - 148.206.53.231

end If Tec!s ~3 ENT the9 beg1 tI

Cace Aux of 1

2

3

4

5

o

9

end; Case nR of

1

2

r-9

3

4

begin VV wC;ntoXY(4,2) vv w'Af;iteStrColor( ' Rojo) V" wGoto><'!<7 2) w w'v*JriteSt:Voliirj' ' Rojo)

end begin

".I wGotoXv(l6 2) W wWriteStrLolori' ' 9qo) W wGotoXY(19 Z),W wWriteEtrCotcrj' ',ROJO)

end, beg in

W wGotoXY(28 2) W wWriteStrColor(' ' Rojo) W wGotoXY(3i 2) W wWriteStrColor( ' R q o j

end, begin

W wGotoXY(4,9) w wWriteStrCoiort ,ROJO) W &OtOX\/(? 9) w wWriteStrColor(' ' Rojo)

end begin

W wGotoXY(l6 9),W wvVriteStrZoioi W wGotoXY(l9 9) W wWrrteStrColor('

' ROJO) Rojo)

end begin

W wGotoXY(28 9),W <vL'Vi i:eStrSo'c;,' \rV wGotoXY (31 ,Si,& vvl"iiriteStri3olor\

Rcj;), Rojo,

end beg in

1V wGoroXY(4 -15) w ~.JVliriteStrfc13ij' Rojc), LV wGotoXYíi 18) w LvWriteStrCoiorí' R J , ~ , ei:d

W wGotoXY(l6 161 W wWriteStrCoior(' Roio) W wGotoXY(l9 16) W ifi,Wri+&trtJolor~ ' P o p ;

begin

end bey i n

W wGotoXY(28 16),W wWriteStrColor(' ,Rolo) v?' wGotoXY(31 18) W wWriteStrColori' ' Rojc,

end

begin W wGotoXY(4 2) w wWriteStrCoiorr-(' Rojo) w wGotoXY(7 2) w wWriteStrCcior(;-' ?OJO)

end begin

W wGotoXY(16,2) W wWriteStrVoior('-( Rojo) w wGotoXY(19 2) w wWriteStrColorí'L' Rojo:

end, begin

W vvGotoXY(28 2) \A/ wV\IriteStrLolor,'-i Rop! w wGotoXY(31 2) w wWriteStrColor( )- Roic)

end begin

Vi wGot~XY\4 9; vv vvV"'riteStrCoiori -í' Rojo) w wiJotoXYi7 9) w w\i\iriteStrColor()- iiojo;

end

63

Page 63: MAGENES - 148.206.53.231

5

6

7

8

9

2nd, end.

Until Tecla = ENT, TraeSelecciGn = nR,

end,

(* TraeCeleccion begin

With \hf do begin

wlnittl I 37 24 TRUEj w0per-i wCu rsorOff

\vGoto,XY(1,2j;wWriteStrColorj' I ',Amaril!oj, wGotoxyj4,3j,\l~WriteStrColor(' I 1 1 O O',MForeGrourid), wGotoXY(1,4);wWriteStrCoiorj' O O O O O' MForeGroundj, wGotoxy(I,5):wWriteStrColor(' O O O O O'.MForeGrouncl): wGotoxyfl:6):wW~riteStrColor(' r3 c) O O O' MFcreGrocir?d): wGotoxy\l ,?);w\NriteS?rCotorj' O O O 3 O',MForeGroL;nd): wGotoXY(I3,2j;wWriteStrZoiorí' 2', Amarilloj, wGotoxy(l3,3);wWriteCtrColorj' 1 1 7 1 1':MForeGround); wGotoXY(13,4)~wWriteStrColor~ O Q O O O' MForeGround): wGotoxyjl3.5):wWriteStrColo:í' O O O O O';MForeGround) wGotoxy(l3,Ej.\JvtziriteCt;Coioií' O O O O O',PvlFor~Gíound), wGotüxyj-i 3,7).wVVíiteStiCoiür< i3 U U O O',MForeC;rounU) wGotoXY(25.2);wWriteStrC;olor(' 3':Amarilio): ~nlGotnxj/(35.3)~wWriteStrColorj' I O O O O',MForeGround). Lz/GotoXY(25,d!i~~\~~r¡t~StrCo!or(' I O O O O': hilFo:el;round) wGotoxy(25,Sj:wWriteStrLülor~ I O O O O': MFüieZrouix.l;. wí;otoxyí'~tj:6ij~w\iVriteStrColoI~' U U í3 O O'. ivifüreGrourid: wGotox~(25.7j:~niWriteStrColor(~ O 13 0 ': 13' IvlForeGround): wGotcXYí1 9) w L k 6-%Ccíor(' 4' .Amariiin). ~ , : \ ~ ! ~ ~ ,, 'I? ;O:,~.-~~l/l'riteStr!3niCr(' 1 0 0 0 I~';MFr;re~~;clii.inc?); \~Goto>íY(: : I lj,ud?YriieStrCuio:í' i ,5 O O '3' MForeGro,iit;dj, wGofoxyj1 ,'lZ).vv~~riteStr¿oi(;i{. 1 ú O i; 0' MForeGround), wGctoxyf1 I :3):wWriteStrColor!' 1 O 0 O (2' fMForeGrsund):

Page 64: MAGENES - 148.206.53.231

Procedure -Pcii-Eros Var S Selection

Fuente Destino String lmagenF ImagePD imagen Tecla byte,

W GWindow nRejilla Byte

n Bse,

Procedure Inicializa+'ar Img Itnayen) Var x y VVord bPg 8 rl

for ji = t) to PIIAX - Y' do foi A = O to Max-Y, do

'nlg"[y Y,] = 1) snd

Page 65: MAGENES - 148.206.53.231

"medure Cnmpiementa(Va; Img lmageni L'ar x,) Word, bey in

tor y = O to MAX-_Y do

begin for X = @ to hl4X-x CIO

Case img'jy,x] oi o imgA[y,x] = MAX-GRIS, 1 31 33 ImgAfy x] = 32 33 62 WíX-GRiS lmg'[y x] = 0

Imp[)? x] = 32 + (32 ~ ImgA[y x])

lmg*pj,x] = 32 - (ImgA[y x] - 3 3

end end

end Ccmplementa *>

Principal *> begin

Fuente = S sSelect(1 7 'Imagen 3'j if Fuente :' " then begin

Asigna Memoria (imagen F) L.eelmagen(lmagwF FCi@nte+' im='i IV 3 pea Imagen (I rn a er F, P A G I P1P -0) :Rqilia = Sc;ecuo;iaRqJilla ~f níiejiiia \2 ü then begin

Page 66: MAGENES - 148.206.53.231
Page 67: MAGENES - 148.206.53.231

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x'r

y PTi.).FCtS' F-3ce5aTniento D y t a i Ip irric.gzrcs {P?!; "2 >. SAM-; Lic. ei i ¿otriputacioii I

i' +'?

(* Filtro Pasa Altas Frecuencias. *:I i********************t*************************+*******x******* .y j rnF* !>ti

iiiiit Fdi-PAlt lntertace Procedure -Pd i -PAlt. I tn pie mentation !J se s L I b-Bas, L i b-Se I, L i b-Ve nt , L I - S e :: L i 3-M E n I ; ,

I ype TipoReiilla = Array/l. 5, 1 S] of integer: (.:o t1st

r* .\

L* : J

7-

PI TipoRejilia = ( (O. o. o, o O); (O, 0,-1: o, O): (O:--l., 5:-1> o;, (0: 03-A, O, Oj, (O. o; 0 o O)) :

22 TipoRejilla ( (2, J 2, U Oj , (8, -1 - 7 -1 O) p, -1. 9,-1, O), (0 -1 -1 -1 O) (O o, o o O))

R3 Tipoiiejilla = ( ti, o, u O O) (o -2 5 -2 o! (O I -2 1 U) (o, o, o, o O)),

(O I -2 1 O j

Function SeleccionaRejilla Byte Var W GWindow

Q b\@e

Function TraeSeleccion byte, 'dar nR A m Tecla Byte begir:

nR = 1 VV wGotoXY(4 2) W wWriteStrLolor('-(' Rojo) \R' i dh tOXY(7 3) w w?VrrSe StrC~lo r r') - 9 ~j:::

~ L M riR recla = LeeEspecialílí !ZU F-9EH kSC ENTJ)

Numero de Rejilla *)

Repeat

Page 68: MAGENES - 148.206.53.231

end end if T?ck :- EPJT then bey i n

Case Aux of I

2

end, Case nR oí

I

2

3

begin W wGotoXY(4 3) \ni \.i:liriteItrTolai:'-(' Rnin: VL' wGotoXY{7,2);,?; wWriteStColor!,') ' 4cjo)

end , begin

VV vvGotoXY(l6 2) W wWriteStrC,olori'-í' Hoioj \ni M3otoXY(19 2\ o/ ~A/\n/ritPStrCnlr?rl'',-' Rqn'l

and begin

VV wGotoXY(28,2) VV wWriteStrColor( -( KOJO!

w wGotoXY(31 2) kv wWriteStrColorj'f-' Rojo) end

end, end,

Until Tecla = ENT TraeSeleccion = nR

end r TraeSeleccim *:,

Page 69: MAGENES - 148.206.53.231

Proceddre -Pdl-FAlt, Var S Selection,

Fuente,Destino String ImagenF imagenD Imagen Tec!a byte n Byte, \/V GVVindow nRejilla BSe

Procedure Pasa AltasíReji ila Ti poRej t Ha), 'dar x y , r n n,i,j Word

begin Suma Integer

for y = O to MAX-Y do fer x = O to MAX-X do begin

if (y ;.= 2) and ( y e= MAX-Y-2) and (x i= 2) and (x €= MAX-n-l! theti begin

m = 1 Suma = O, for J = y-2 to y f 2 do begin

n = l for I = x-2 to x+7 do tq!n

Suma = Suma + ImdgeriF"i( ij Ke,iildjr:i ni mc(n)

end Inc(w)

end, if Suma ;= O theti begin

if Suma c= ILIAX--CiRIS t h m

el5P irnagenEfi~j8 -- qiiryz

irriayertrifi[y = rmi(-mS m d

Page 70: MAGENES - 148.206.53.231

Principal *) bep7

Fuente = S ;Select;? 1 ,'imagen ?I),

if Fuente <> I ' then begin

4s ig n a PA e tmo r i a ( I m aye i? F) Leelmagen(1magenF Fuente+' ;ma') Ma pea i ma g e ri (I mag en F PAS I i'd A-6 ) r) He] i i I a = Se I ecc io na Re) i I I a if nRejilla .==. O then beg in

4sig ii a Me tno ri a ( I m ag en Di, Vv wlnit(l,25 40,fS False, W wOpen W wCursorOff 1V wVJriteStrColorf F1lt.c Pasa Altas - TR4RAJAPlDQ Cace nRejJilla i3f

4mqnllo)

1 PasaAltas(R1) - 7 PasaAl tas( RZi 3 Pasa 4 Ita sjR3)

end Ma pea I tna y e n (I in ay e n D P AG I N A- 1 ) I W wLiose VisualizaPagina(1) n = O Repeat

Tecla = LeeEspzcial([EVT ESC]) if Tecla = ENT then beg in

VisualizaPagina(n) if (n = 1) then n = O else n = 1

end, Until Tecla= ESC V iwal iza Pag i na í1) if Deseasalvar then begin

Destino = TraeNombre + ima' if Length(Destinoi > 4 then

If Not ExisteAicti(Destino) then

else Es,-riDelmagen~lmag..rln Dest!na)

if Co inti rniacio t i (Desti no) the t i

Escribelmagen(imagenD Destipo; end LiberaMemoria(lmager;D)

end, Li beraMemoria(lmagenFj

end

Page 71: MAGENES - 148.206.53.231

R3 TipoRejilla = ( (1 1, 1 1 I) (I 2 2 2 3:

Function SeleccionaRejllia Byte Var W GlVindow

O byte,

Function TraeSeleccinn byte 'Jar nR A i m Tec!s Byte begirt

rik = 1

W wWnteStrColorí'-j' Rolo) 1%' "GotoXY(7 2), VY wVu'riteSt:lolor('\ ' Rojo) Kepeat

Numero de Rejilla 7 VV wGotoXY(4 2 )

Aux = nC?

Page 72: MAGENES - 148.206.53.231

end end, if Tecla <> EPJT then begin

Case Aux of 1

2

3

end; Case nf? of

i

2

c 3

end, end,

dntil Tecla = ENT TraeSeleccion = nR

end Y TraeSeleccion 7

beg in With W do beg in

wlnitíl I ,57 I 1 TRUE) wOpen WC u rsorOff

beg in W wGotoXY(4 2) v\/ wWriteStrColor(' ' Rnjv' W wGotoXY(7 2),w \ , \ / \ ~ ~ r i t P S t r C ~ l ~ f ~ ' ' ROJOJ

end, beg in

W wGotoXY(16 2) W wWriteStrC:olor(' ' Rojo) W wGotoXv(1ci 2) wYVriteStrColort' ' R q e )

end, beg In

W wGotoXY(28,2),W wWriteStrColor(' ' Roioi W \/\;GotoXY(SI 3) iV wWriteStrColc~rj' ' Rojo)

end

73

Page 73: MAGENES - 148.206.53.231

Proceaure -Pdi-PBaj V x S Selection

Fuente Destino String ImagenF !magen9 Imagen Tecla byte n ayte \iV GWindow nRqilla Byte

Fiociedure ?aSaBajaS(~ejilia TipoRejiila ü i~ i so r I:iteyer), dar x,y m,n iij VVord

begin Suma Integer

for j = O to M A - Y do for x = O to MAX-X do begin

if :v >= 2 ) and (v <= MAX-Y-2) and ix >= 21 and ix <= MAX-Y-2) then begin

m = l Suma = U for j = y-2 to y+2 do begin

n -= 4 for I = x-2 to x+Z dc beg in

Suma = Suma + ImagenF"u,ii ' Keliliajm nl lnc(n)

e.id incji ni

end imagenD*[v x] = Round(Suma div Divisor)

end else

I i n a y ~ t 7 D " i y , ~ ] /~1i iye~7Fs[ j A]

wid, end :

74

Page 74: MAGENES - 148.206.53.231

i* PririGtpai *; beq I rl

fuprlte = S sCe lx t í l i 'imagen ?': if F~iot-ita -- " t h e n begin

Asiyt7aMetnoria(irriayeiiFI Leelrnagen(1magenF Fuente+ ima') Mapeairnagtin(lmagenF P4GIN4-O) nQejills = Selc'cc!onaRejilia if n4yilia .- G ti-ieri beg in

4 sig na Me m oria (I mag en U) \Al wlwtjl 25 40 25 False) W \.;CI.Fen, LV wi; u FsorOff, W wWriteStrCo¡or( Filtro Pasa Balas i R ABFtJ AiqGc, Case nRejilla Of

H ma r i i io)

i PasaBajas(R1 Ci), L lasaBajas(K2 In;, 3 PasaBajastRS 36)

end Mapealmagen(1rnagenD PAGINA -1: w LVClCISt

Visus.lizaPal;Iria(?) n - O Repeat

Tecla = LeeEspecial([Ei\IT ESC.]) if Tech = ENT t h e n begin

VisuaiizaPagina(:ii if \n = 1) then 1 1 = O e k e n = 1

end Until Tecla= ESC VisualizaPaginail; if Deseasaivar then begin

Destitic = Tw4o t -n tm + {mu' if LengthjDestino) : 4 then

If Not ExisteArchiDest,no) tnen

else Escr ioeima()en~lmage~~, Destino)

if Confirmacion(Dest!no) then Esci!belmacrerrílrr,agei?L Destino,

end L I be ra Fvl e IT^ o ria ( i m age n D)

end Libera Mernori a { I mage n F)

end e t i d :* .-Pdi-"PBal *} hegin en3

Page 75: MAGENES - 148.206.53.231

Unit Li--Bas; Interface Const

Page 76: MAGENES - 148.206.53.231

I ; , P=ileta p2r2 el iriqn-j? de 64 :clt-r-)5 dc? fsr,: '; "-rc;-i( Ire 'nt:iai;caFi>3!,~:~ I Lee ur,a krldger, CL 9 i s ~ *, Procedure Leeirnagen(Var iniag iniagen i\)ornArch String) f* Salva una imaqen en Disco *) Procedure Escribelm3genilmag itnagen NotnArch String) ;* Mapea Lina Irrayen en RAM hacia dna pagina de la hlemoris de Dec-$isge *} Plo¿edure Mapealrnagen(imag Imagen, nPag t3j.t~) i' Asigna Memoria en el Stack para una imagen *} Proceaiire Asigna,Zilernoria{Var 1n:q irnxgeti) P Libera la Memoria asignada a una Imagen 7 Procedurii LiberaMemoriaiVar Imag Irnag;.;?; it Lee PCualquier Tecia del Teclado *} Function LeeTezla 19iord

I" Lee Solo Las leclas Especiales del 7 eclado ') Function Leetspeciai(Conj ¿onji!~toE;~tes) b$&e i+ Escribe iin pixel en el monitor *} Prxediir.: EscribePixeijnir-Offcet LZ/ord,Rcno,lon Col:i+nnn;r Wv.! rolor Rytr-j i' Lee uii Pixel del rncmitoi J Fuiiction LeePixeiiGii-Gtfset Word Renglon, Coluinna Wordi Byte i* Visualiza la Pagina que se la indique *} Procdi ire VisualizaPaginainPag Byte)

-- I /

Í i

Page 77: MAGENES - 148.206.53.231

I!?! i ;Tip; dx,2.Z jFJ3E"

o 11 t dx. a I inc d. in aÍ d:.: arid ai.tiot OEh or sl,Oilti out dx.al rnov /JY GC--INDEY rncv al.GRAPHIC§ f\/iQDE out &,ai 1ric dx in al.dx and a!. not 10t-i out dx.al dec dx mov a1,MISZELLANEOUS out dx.al i n c ds in al.& and al; not u2h out dx,al mov dx SC-INDEX mov ax, (Ofh shl E) 4. MAP-R/IASK out dx, ax mov ax.L'GA-StGMEluT mov es;ax s u b di di mov ax,dr tnok cx.SOO0h cid rep stosw mov du. CRTC-IN DE)! mov a l ~ M AX-SCAN- 1.1 NE out Uxai inc dx in al dx tymv 31 ? act dX,Ui áec dx mov a1,UNDERLINE out dx.al i n c dx in ai,dx and ai, nor 4uh out dx,al dec dx mov aí,MQDE-C¿7NTROL Gut dx,al inc dx in al dx or al 40h out dx,al 2nd.

,\

inov a I , M E 61 o R Y- M<J 1, t_

-

(*ForiModo320x20(S._L'5~~j

Page 78: MAGENES - 148.206.53.231

Procedure VisualizaPaginaínPng We) Assembler ASM FIG\, bh nFag crnp bh, U JZ @PAGINA-O cmpbh 'I jz @?PAGlN4-I cmpbh 2 JZ @PAGINA-2 cmp bh, 3 ]z @PAGINA-? @ P AG 1 N q-2 fmov PAG-ACT bh mov bx, Li000t-i jmp @INICIO

P9G IN A- l movP4G JICT bh rnov bx 400011 ~ir ip @ir\iicio @PAGINA L rnovP4G - ACT bh mas' bu SCPOh ]trip GJNii;lO

mov PAG-ACT bh mnvbx Qc@U@h imp @.iN~CiO &iN/Z/L? mov dx Cí-? fC-INDEX add Dx START-ADDRESS-HIGH t m v a r Dx out dx, ax end

(*VI sua I iza Pag I na*)

@i?PHGihA-3

P t oced u re Esc ri beP ixe I ( Di r-i'Ycet !\ford 9 i n g lcn 201 ti m ria Word Pc'l? fi ,te; C-P I T? h I C r

ASM mov di , LJir-Gffset mov ax LGA-SEGMENT rnov es ax mov ax SCREEN_WIDTH/4 rncv dx Renylon tnui ux rnov YX Columna push cx shp c:: 1

st,, ¿A I aud ax cx add di sx

Page 79: MAGENES - 148.206.53.231

Function LeePixeI(Dir-Qffset Word Renglon Columna Word! kvte HSSelrblei 4 s M mov S I Di;-%fsrt imov dx, Renglon (* Goordenadas ciei ? i ~ e l 7. mov cx, Columna mov ax VGA - SEGMENT

nick' al% SCREL-l\i-?'VIDIl I/.? mLii ax push cx shr cv 1 s b r cx i add ax. cx aad SI ax (* SI i- Offset * j POP ax and al Qx

m o ~ ah al mov ai REAE-MAP rnov dx GC-INDEX out dx ax wov al byte ctr (es [si]) i+ Lee ei valor del P i e l +I

rnov es 3 Y

end Zf"LeePixe1')

Page 80: MAGENES - 148.206.53.231

Procedure Escri helm agen ( I t m g I magev Notn A rcb Stri vg ) liar ArchGinario File

beqin leidos wGra

Assign(Arch6marro NoinArchI R eWr i te (A rc h B I I> 3'1 o 1 ) Bloc KIN; t-, (A rch 61 r m o j m ay TAh1-I mag lei des) í;lose(ArchGinal IO)

end ~Esc r ibe imagen~

Froceduie AsignaMerncria('dur 1 1 rid3 irnagrrij ueg I t?

New( Imaa) ?rid [/* 4 signa M c maria*

? t oceci u re L i bet a Me ir 1 c, r I a (U at I rn d y I may e I I I

beain

eirf ,I' i i be raM ern o I i a*rj

diwosePnnag)

Function LeeTecla Word Assembler .A s AA moban 1 int 1 6 h JZ @FTiQ s u b a h ah int 1317 end

rLeeTecla"1

@€?!a

FL: nct io r i ee Es pec I 3 I (Coni Con] u ntoeytesj byte Word I , TeclaEslj

ba11w Boolean, Parte Alta P;. rte Ba! a Byte

Sand = False Repeal 1 eclsksc = !_ee?er,la

t'Pgi1:

81

Page 81: MAGENES - 148.206.53.231

6a t i d = T f? U t ~eeEsper;iai = FatteAita

it Fartedaja in Con] then beg in

Band = TRLIE Lt.eEspe;ial = ParteBaja,

end

th Inicializa La Paleta para 54 Niveles de Gris *') Procediure InicializaPaleta Const COLOR-RESISTERS = 5 4 , Va r

Froced tire ValueToSetiV byte) Assembler I w e

ASiLl movah 10h tnov ai, 10h mov bx word(Vj rnovdh V movch V 1';10?1 c1 'J Int 10h end

(* ValueToSet *:

Procedure Activa?agiiia(tiPag byte) begin

PAG -ACT = nPag end y 4ct:va%g!na *I

Page 82: MAGENES - 148.206.53.231

Pruceouie ÜctaiizCyXL? Sci Delta/( ilelta'r' inteyer Xhirectioti integer Lolot 6ge) V a r Lelm Y xl" UeiTaY x2MinucUe!taXx,' Error rerm Integer b g i n

DeItavx2 = DeltaY * 2 Delta'(x2MinusDeilaXx2 = Delta':'4; (DeitaX'2j ErrorTerrri = Delta í x2 - UeltaX EscribePixel(Dir- PP,G__ACT YO XO Color) DeltaX = DeltaX - 1 i"!hile UeltaX : O do begin

if ErrorTerm >= O then beg in

)'I1 = y@ t 1 ErrorTeitn = Errorlerrn + Del:aYnZ~VIiiius33lta,~~2

end else

ErrorTerm = ErrorTerm + DeltaYi2 XO = XO + SDirecticn EscribePixelíDir-Pk2-AZT YO, XO Cvioij, DeltaA = DeitaX - 1

end

OctzntO *: ?nd

Procedure Cktantl (XO. YO. DeItaX. UeltaY: Integer. XDirection. Integer. Color. Byte) \/a r De I taXx2. Del taXx31L1 i n usDeltaYx2, Erío rTerm, I iiteg er, beg¡ 17

DeltaXx2.- EeiiaX *- 2; C>eltaXxiMinusDeltaYx2.= DeltaXx2 - (DeIta'r'+2) ErrorTerm-= DeltaXx2 - DeitaY. EscribPPix-el(Dir-P.~G_ACT W ?(O. Color! Delta?'.= CeltaY - 1; W d e UeltaY 9 U do begiri

if ErrorTertn ;-= O then begin

SO:= XO + Xciirectioii. ErrorTerrn.= ErrorTerin + CeitaX~2MinusDeita i'xf

end else

ErrxTerm = E:rorTerrn t DeitaXx3 Y0.- YO + 1; EscritsePii<elíliir-PAG_ACP YO. XO Coiorj; Delta?"= DeltaY - 2

end en:!; p ?-l .pntq *3 I u'- J

Page 83: MAGENES - 148.206.53.231

PruceJLiit iir,eG$Q ','a XI ''; :r:tegei 2 val lt?¡-rip DeitdX uwid I i;tlegei beGin

3 f yo 3 Y1 th=p 7 P ' 3 < ?

Ternb = YO Y&:- fl Y1 = Temp Temp = Xc? XI3 = XI X: = Terr;p

end DeltaX = XI XO DeltaY = Y1 - YO if DeltaX . O then begin

if DeltaX DeltaY then

else OctantO(X0 YO DeltaX DeltaY, 1 Color)

Octant1 (XO, YO, DeltaX DeItaY, 1 , Color; end else begir;

DeltcrX = -DeltaX if DeItaX : DeltaY theri

else OctantO(X0, YO DeIlaX DeitdY -1 Cciiorj

Octant1 (X@ Y@, DeltaX DeltaY -1 Colorj end 2nd Linea *)

(2nd {-Li b-Eas*)

84

Page 84: MAGENES - 148.206.53.231

(" 8 pixeles en X por 8 pixeles en Y' = 64 pixeles por Caracter * j Caracterox8 : Ar!ay[ü 7 0 Char const

( i t

,, Coiljunto Set Qf Char = [' ','A' 'Z' I , ' ' ' ' _ , , { / ' - @",'&" -'I I

I , t,,, <*< .,' , , a I I , , ,

FlecnaArriba Caracter8x8 = (

i X' ' xxx, 8>(xx>íx' 'XXXXXXX' I X'

I ')

Punto CaracterSx8 = ( '

' xxx ' xxx

Qoc>Puntos Caracter8x8 = 8 x x ) ( 4 XXX

' xxx ' ' xxx '

I

85

Page 85: MAGENES - 148.206.53.231

Interrogacion Caracter8x8 = < 'XXXXX I

'XX xx' ' Y"X ' ,

Xx I ,

I xx ' ?

Underscore: Caracter8xG = ( '

'XXYXXX ' ' I ) ,

Asterisco CaracterGx8 = i ' ' X Y X ' ' xxx I ,

' X M ' , ' X X X '

Parentesislza Caracter8x8 =

* x x 'xx 'xx I ,

'XX I

# xx

1

Page 86: MAGENES - 148.206.53.231

Ad m I raz i on A bre Caracte r8x8 = í

I X X '

' x x ' 4 >v( l > o ( '

I xx I .

' ')

Menos. Caracter8x8 = (

May8x8 Array r A ' 'Z'] Of Caracterllx8 = ( A"B c, D I J E IF 'G 'H I J' K' L M NI 'o P Q , R c r u I' w Y, Y z 1

NcimSx8: Hrray['O'. 'Y] Qf Caracter8x8 = 9' 1. \ (j,,',?, :,J., t4,, :$, '7 j , : 8 : , ,

1 tn ple isle ntatioti beg in end

Page 87: MAGENES - 148.206.53.231

Tonos de Gris para la formacion de los menu *? MBackGround byte = 52 MForeGround byte = 35

MTonol byte = 33 MTono? byte = 53 MTow3 byte = 63

rY Pe Orientation = (Vertical Horizontal NoOrierit), Buf = Array[MIN-_v M A X - _ i itllN-3 MAX-%] of 6yte PufPtr = "B::f, QueliePtr = 'QueLieNode QueueNode = Record x Y BSe QpStr String C p N u m be r Lori y I nt ¿olor byte, Next Prev GueuePtr m b ,

GMenu = Object A4X-l My1 klx2 MY2 Byte, Mhuffer BufPtr MBack MFo:e, MXc u r, Mycur Byte MQPtr QueuePtr rViC?rient Orientation h lhr rent QueuePtr. Procedure iviItiit\x1 y1 x2 y2 Eyte, Orient Oiietitationj ?rUcedure Müpen Procedure Merase Pr~cediire Mdispose Piocedurc PVlCiosc Prucedure MGoeoXYrx y byte) h a z e d u re khvriteCha íiL t i c h a r i

88

Page 88: MAGENES - 148.206.53.231

D: Ch3r 1.3l~: By??) Frsw d u v ?dbv r ,tLiCtr;St Str i rig), Frocecidíe ibivvriteStiXYix y Byte St Stritny) Procedure MwriteCtrXYLolorix v b+,rte Ct String Color Dvtei ProcedurG Mwrit&ox{~Bo~ yBox fi ByTe) Proredurr; PV/l:A;r\:r;tei-'q3ioq:X

Froceaure Evlyopc33ptioi i(xt3ox yt jox Byte ti uytel Procedure Mitem(xBox box Byte OptionStr &trina Optionluumber Longlnt L byíe) Prúcedi ir? Mwritelterns Píccedure MFreeQuei ie Procedure i\illiyl~t(Soior xBoih @ox t i Byte), kunction klSelect Longlnt Procedure Il/lí=lear Procedure MputFrame prccedlrre h/i?utArro;v, end ;*G Iden u 7 Procedure ClearMenuRegion(x1 ,y1 x2,y2 Lolor byte)

5;te QpCtr 'String c +?$e; P I J G ~ ~ J Í ~ XlFusi~Cptiot,(XBox BOX Eyte ,I E$ej

Implementation

Procedure GetMernBuf\var P Bytes Wioral var Pt Pointer absolute P begin

GetMem(Pt Bytes) if (Pt -- nil) then bey i ti

Regresa AmodoTexto Writeln Write(' Error f 1 tvlemorra insuficiente Haití?;

end, end <*Get h4 e m 6 11 f *}

.' j;

piocedure FreefvIeinGui,v.da; F Byks 'd'dbrdj

\lar Pt Poinrer aosoiute F beg in

I f Pt <' !>!I the!? CrceklemjFt, B)tes),

end, F ree Me rn But*)

Yoczddrs ClearMenúRegion<xl yl xi,yZ,cioior YLte; dar x y Word, beg in

for v = ((y1 -1 )*I 3) to ((y2*131-11 do beg in

for x = ((XI -?>*a) to <(x2*Bj-l) do beg in

end EscribePixel(Dir- P4G 4LT Y x Golor) end end

2 I ea rR8e 17 ii Reg i cm *)-

y GMenu hkthod's " )

89

Page 89: MAGENES - 148.206.53.231

ProCeudis Gmenci iditern\~xBox,yBox Byte C)ptionStr %lag

Var Auxl Aux2 QueuePtr beJic

Optioni\Jumher Longlnt C Byte)

it I\ilQptr = nil then begin

NewlMOptr) I\ilQptrA x = uBox

MQutr' CipStr = CipiionStr MQptr" OpNumber = OptinnNumber MQptr" Color = C MQptr" next = MQptr [VlQptr" Piev = MQptr

i laptr" i ~ B J A ,

end else beg in

I\: SW(A IJ $1 ) Auxl" x = XEOX Huxl' y = yBox Ai ix l OpStr = OPtionStr A w l OpNumber = OptionNcimber

ALIA" next = Auxi Auxin Prev = Auxl Aux? = MQptr While Aurt2" Next Aux2" Next = A u x I , AuxlA Prev = AuxS 4 ~ x 7 " Next = MQptr MQptr" Prev = A u x l

.bkl ' CSolGi = c,

MQptr do Aux3 = Aw2" Next

end end i*Mitem*)

Page 90: MAGENES - 148.206.53.231

Procedure Gmenu MFreeQueue Var Atix QueuePtr begin

if hlclptr :: txl ttieti beg i fi

Aux = MQptr* Prev, While 4ux ---: MQptr do begin

A ~ i n AukA Freid, Dispose(Aux^ idexti

end ¡3Kp@5eqI\4OPtl,

end I t iu ?' llíl'-rPeWLlecie-:

91

Page 91: MAGENES - 148.206.53.231

Procedure Gmenu MDispose heg i n

Free R1 e m 6 u f (¡?A b J ff E r if'*.lnl Mkl -I ) * '3* (PA j 2 - y; + 1 * ' 3) kl í reeu u e ü e

end r'MDispose*)

Frocrd ii re G hle ti LI hflCiosr czgin

MErase, Md is pose

erd M C I ose*;

92

Page 92: MAGENES - 148.206.53.231

93

Page 93: MAGENES - 148.206.53.231

Procedure GMenu MwriteStrjSt String) Var i integer begin

For I = ? to LengthjCtj do begin

St[i] = Upcase(St[i]I h4writeChar(St[i])

end, end i*MwriteStr*}

Piuceuciie Gídleriu iblwi iteStrXYYCoioi (A j byte SL Stririy, ¿oiur byte! 'Jar I Integer

Page 94: MAGENES - 148.206.53.231

Procedure GMpnu MwriteOptionjx,y Eyie,OpStr String, C Byte) begin

{rvlgotoXY(x y) 1 F1/I~~ritc?~trX\I'Color(r,, y , LlpCtr,;) MwriteBoxix y Lznylh(OpStr)+-i I

end ~44wr i teOpt ; r i r ;~~

95

Page 95: MAGENES - 148.206.53.231

Procedure GMenu MPustiCjptioriíxBox yBox r j Byiej llar x y VVcrd begin

yEoi = yBor-I if (XBOX 3 I) then

XBOX = XBOX-1, v = (íMyl+yBox-l )*I 3+1) for Y = í(Mr1 +xBox-I 'I%-4) to ((Mxl +xBox-I )*3 +8+n; do

Escri oePixel (Oir-PAG-RCT ;i,x, VBackG rou nd),

for Y = ((Mxl +xBox-I 1*8-4) to ((Mu1 +xBox- 1 )*8 +ü*n) do EscribePixel(Dir- PAG-ACT y x MBackGround)

Y = (l\,I~'+xlo>: 1)*4

y = j (M~ l+~B0~-1 ) *13+1 lj

F,. I U ~ ) y ;(!'v?)? ')GO;-, l ) * l z + l ) tG ( ( f ' d j j l +yBox-l)*lS+:O) da -scriSeFi~el~Dir-PkG_A¿T y x MBackGíourid)

x = (~lxl+xBox-l)*8+n"8+1 for Y = ((MyI+~B0x-l)*13+1j to j(Mvl+yBox-li*13+11) río

Ese r i hcP ixe I (O i r-P P S-P CT 3 Y l\J Rack G ro 11 n d ) M!iyt-it(Eoj~ AEOX,~BC)X t I )

e m { * M Push Clot ion " )

Page 96: MAGENES - 148.206.53.231
Page 97: MAGENES - 148.206.53.231
Page 98: MAGENES - 148.206.53.231

,-\

L

' 6

7

8 end

end, incii), end,

end, r M p ci t F ra me*)

for x =

a for >: =

9 for x =

7

end incii)

end

99

Page 99: MAGENES - 148.206.53.231
Page 100: MAGENES - 148.206.53.231

F :i P ;+i c, *? Trae No T b rc? St r i n g , Fclr,cti=i I DrseaCalvar Boolear;, Function Lonfii niaciori(t\iom String) Hooieari Functicn ExisteArch(Nom String) Boolean FLtpctior GetStríVar W GV\jindo\.~i x y @te Prompt String \/3r C: Strins I on-5 Elite Fi3ar:leS-t 2 t .CfC h a rs) Boo I ea i; , riinction TíaeOrigeiiíVar Xo, '1'0 Word) Boolean Implementation

c -+

Page 101: MAGENES - 148.206.53.231

F. II t iction ExisteArch (Nom String) booiea t i

var f file t k g I ii

{S I ") Assigníf Noii 1 1 ,

Resertí) Cloceíf! :si+> E:;ictzArch = {!CiKesLilt = O) and :PJotn - - "1,

end, (* ExisteArch A }

FJnctioti SetStrjVdr W SWindov,, I\ y By?e P!¿irnpt Stririi; ' I a 5 S:rir,y, , L , I I ~ V 2j.z

beg in EnabieSet SetcSfCharsl Booleai I

GetStr = L4j-SE s = 'I

'"Yiih L" di: beg1 t i

wlnit(x v x+Length(Prompt)+LongS+2 y+? TRUE) WU pe n vvCüisor0í-f w\n'rireSt:(Píornp~ wCu rsorOti if Not wHeadStrLengthiS Longs EnabieSet) then Exit WC u w 3 r Off

e n d , GeStr = TRUE

ena i* -?etSt: *)

Page 102: MAGENES - 148.206.53.231
Page 103: MAGENES - 148.206.53.231

beg I tl end.

Page 104: MAGENES - 148.206.53.231

Ty pt siueueptr = *sQueueNode Str8 = String[8]

{+++ Selection Method's +++)

Page 105: MAGENES - 148.206.53.231

p,.: 10'- '7

i h i l

else be; i ii

Mi! tern i Y. r , sC u r re n t". Nom , r , MI F. o reC; round : in& SCi!rreW= sCi.irrent" Next

< + - i t .- B , ;

if (sSui'rent .L sQpitj t ! w i beg in

Mitern@? S Y + *) NumberC>flterns+3 '&'.FLECHA -4RRIB4 Amarillo) M it? m {4 , SY + 3 N u 177 be r 0 f l te yn s + 3 'a' , F L EC H 24-,4, E 4 J 0 4 IT 3 ri ! 112 i

end; iulG pe n , if (slurrent = suptrj then

MPutFrame MwriteStrXYColorj3;L,sTit, Rojo;, sapen.= TRUE.

M wri test rXY Go lor (3 . r , '--FI N--' U) 1

end. end. Csc! pen *>

Procedure Selection s l iose begin

MClose, s DisposeCIu eue .

end r"sCiose*)

Procedure Selectiori.sMakeClueue; Var üirlnfo. SearchRec;

Auxl >Aux2. SQueuePtr: Currentüir. String,

SetDi r(O, Cu rren t Di r ) , If LengthíCurrentDir) = 4 then

else CurrentDir.= CurrentDir + '\*.lma': FindFirst(CurrentDir,Archive,Dirliifo); LVnile DosError = O do beg in

begin

Currentüir:= Currentüir + '* lrna'

New(Aux1). Aus? .lorn.= CopyjDirinfo b!zrw,I Pos:' ',Dirinfo Nams)-i) 'j?Ji.iiIeiLeiigth(Auxl ".Noinj L-. 8) r l ~

if sQptr = Nil then begiri

Aux.i"YNotn.= Aux?".rJoin i- ' I ,

stzptr: y A 1:xl Auuxl Prm = Auxl ALMI .':.Next.- A u x i

end

Page 106: MAGENES - 148.206.53.231

P roced u re Se I ect I oil I O I 5 uoseQ e LI e ’<ar riuv SCiuewPtr, begin

if sQptr .--. nil then begin

4ux = se2-itrA Prev While Auk -: sQptr Jo begin

Aux = Aux” Prev, DisposeíAur” Next)

end Uispose (sQptr)

end end TsEisposeQueue?

Function Selection ssetectjx y byte, Tit StriKgj String Var

begin

Hux r ionglni PtrAux CQueuePt: I hvte

Page 107: MAGENES - 148.206.53.231

begin end

Page 108: MAGENES - 148.206.53.231

\JV-- MaxC = 40 'tW-rVlaxR = 25

p Maximo Numero de Loiumnas en t ina Ventana *: Maxitno Numero de 4 e r . i g l n ~ 5 st? I Ina \:en+at-i3c ?

,.* Tunos de Gris ' j 'VVBacKGrounn byte = 52 WForeGraund byte = 35

','VToriol byte = 33, WToiio2 byte = 55 VVTwno3 oyte = 63,

Page 109: MAGENES - 148.206.53.231
Page 110: MAGENES - 148.206.53.231
Page 111: MAGENES - 148.206.53.231
Page 112: MAGENES - 148.206.53.231

Procedure GWindow WVVriteCharjLh Char) V a x y Word begin

i í Ch in [a' L'] then Ch = Lnríord(<;ni-321 if (Ch in Conjunto) And (Wxl+Wx¿ur begin

if Wcursor then WDelCursor

begin

Wx.2-1) then

For y = o to 7 do

For x = O to 7 ao begin

Case Ctl Of

i 1 3

Page 113: MAGENES - 148.206.53.231
Page 114: MAGENES - 148.206.53.231

F' I Gced re GVV i tid O'M '&\r;rite SIri St St T I n 91, Var i Integer, begin

For i = I to Length(St) dn hec;in

if St[ij in ['a' '21 then St[i] = C!-ir(oid(St[!jj 3fj, VVwriteChar(St[i))

end ertd :"Wt.vritPSt:*;

P roced 11 r3 G Wi n d ow. W w r ite St rCo I o r jSt Str i 17 g Ct, I n r , B ytei \j2r i 1ntegi.i; beylii

tor I , = 1 to LengthiCt) do begin

if St[i] in ['a'. 'z'] then St[¡]-= Chr(orriíSt[i];-32) W,vr i teC h arCol o r (St [i] , ,C.z! o r) :

end. enci, i'WwriteStrColor7

Procedure GWindow 'WreaáStrivar S. Striny): Var I ' Byte.

Ch- Char; InicPosX. SyZi..

s.= ": I = O

Ueylll

ke!,ea!' ¿h = f.-t?rí! o(I ?-te I ecl2!;

Page 115: MAGENES - 148.206.53.231

Function GWindow VVreadStrLength(Var S S t r i ~ q L Byre Eset Set@tCharsi Boolean Var I Byte

Ch Char inicPosS Byte

s = 'I

I = Q \Ai read St:!.? n g t I- = F P L S E, IiiicPosX = WxZur, if Wcursor then VVwriteCursor Repeat

begin

Ch = Chr(Lo(LeeTec1a)) i f Ch = fi27 then Exi? {+ UpCasejCn) 7 if Ch in /'at '21 t hen Ch = Lhr\orn(cti)-32) if (Ch in Eset) And ( I -;= L) then begin

incii), SIi] = Ch WwriteChariZh!

end else

if (c l i =- #ZS> And i \ i?;Lu~ ln,vPos:<i :i ,cr, beyirr

VVxtur = VVxCur - 2 LVwriteT ha r? '1 *f \'L'ri;rcay the- ,Vd= 7 !r

it Vvcursur trieii ~ i , \ d r i l e ~ u ~ w i

, I , LLXU,: = 'V;'ASU, ;

i = i . 1

Page 116: MAGENES - 148.206.53.231
Page 117: MAGENES - 148.206.53.231

-1 ]* 7royecto Procesamiento Digital de Imagenes (PDI) {A UAM-I Lic en Computacion *)

k)

r

{SO+ F+}

I

*? I

lnstalacion del Overlay Manager ,~+++tt*+****t***t+**+*+************+****+*++~+*~+*+**~*+****+++****+~+~**+~+t+t*~~ I I

Uni t Menu. Ovr I ri terface 'mplementation Qses Overlay begin Ovrlnit('Menu OVR') if CsvrResult =c> ovrnk then bcy i 17

cdse 3viResult of ovrError WriteLn('Program hzs no ob/erlays ') ovrNntfound WriteLf7j'Overlay file rot found '1

end , t-ialq I I ,

end CvrClearRirf e d

Page 118: MAGENES - 148.206.53.231

Procedure Pdi-CMas V=I~ S Selecttoti

Fuente, Desti PCI Stri PJ, ItnagenF ItnagenD ltmgen n Byte Tecla Byte \nl Gwivdow

FLierite = S sSeiect(1 , I 'MasK 7 ) if Fuente I f then begin

kegin

AsignaMetnoria(imacenF) Asignai\llerno:ia\lmag~~D~ Leelinagen(1tnagenF Fuente+' itma j W winit(1 25,30 25 False) W wOpen W wCiirsorC'ff '&' W'VV rite CtrCo I or Cot 11 pi e tn e n tci Mascar I I 1 a T r3 Conipiementd jliriageri~, lrriayenü) W wLlose Destino = TraeNombre + ' Ima' if Length(Destin0) 4 ther

If Not ExisreArch,Dest!rioi ther;

else EscribelmagenjlmagenU üestino!

if ConfirmacioníDestino) then Escribelmagen(lmagen5t Destino)

LiberaMemoria(lmagen0) LiberaMemnria(imagenF)

end

-PAi-CMas *> end

begin enu

Page 119: MAGENES - 148.206.53.231

~ L I i ir+ion T:W'?iiiul-ro GYte 431 lJ10 Girlenii neyin

With MO do beg I rl

Minitjl , I 32 3 Horizontal;, Mltem(l2,2 ' I : ,Pu.lForeGround) I\/litem(li 2,' 2 ' , 2 MForeGround! Mitemí22 2 ' 3 ' 3 MForeGround) Mitem(27 2 4 ' 4 MForeGround! Mope t i ,

M P u tF ra m e, ivl writeStrXY Color( 2,2 Nu mero 3 Rolo 1 TraeNumero = Mqelect MClosc

enci end YTraeNu mero*}

Procedure -Pdi-Desp Var Key bvte

n I byte \$El/ G\h;l:;dU\'/, W2 Gvvindow, S Selection

Page 120: MAGENES - 148.206.53.231

et:c. 9 J begin

ÍdcxribreiLj = a S k i e L i i ; 1 'lmagei-I 4 if Nombr43] = ' then I = 2 else I n c Í , )

end end

Until I ri 4 s I r~ r! a bl e m or ia [ I rn ag j \iLQ V ~ ~ ! I ~ I T ( I 34 d0 25 Fake) ??/2 ~$:cpc': itv2 L";L~isorOfi, VVL VVG~XOXY ( I , I ,J W2 wLlVriteStrColor;' Cargando Irnageníesi Amarillo) For I = n-I Downto O do beg IR

Leelmagenjlmag Kombre[i;+' lina'j if I= O then ' V E wLiose Ma pea i mage ni (mag I ;

er?:? L,beraMemoria(l tnag), !-u Repeat

VisualizaPagina(i mod ni W i t h VV 4c begit?

vVimt(1 1 IO 1 False) Wo pe n wCursclrOff WGOtOXY(2 1 ; vvVViiteStrColor(Not nGrr;[i I T I U ~ i I] AI IS, iIiüi ney = LeeEspecialj[Ebii ES¿]! Wclose

end ; = i tl,

i i r i t i l K e j = ESC end :* Pdi -Dew *) b g l P

er8d

Var v Selectlor

Page 121: MAGENES - 148.206.53.231

C* Provecto Procesamiento Digital de Imagenes íFDIi *} J* (JAM-I Lic en Computacion 3 i* i

(* Para Leer irnagenes en Oiro Foi;riutG í***X*t*t****r***+l ti* ***ti**** t* ********++++ tt**+f,*i+*****il ''I

+?

+ I

4%F+ O+\ I 'nit Pdi-í'fmnt ',;trIfu¿2 Procedure -Pdi-Gínit, I rn pie mentat ion Uqes Lib-Bas Lib-Sel, Lib-Vent Lib-.Sec

Type TypeRenglon =: Array[O 1 5001 of Dytr

Page 122: MAGENES - 148.206.53.231

Procedure Inicializa(Var I Imagen)

begii-i v3r >( y \A¡c)rd

For y = U to MA)\-Y d o For x = O to MAX .X do

l*[y x] = O end r /nlciallLa *;

Procedure C-opiaiR TypeRenglon Var I Imagen nHenglon Nard nbytes Woro! Var x Word beg in

for x =- O to nbytes-1 du l"[nRei-qlon x] = H[x]

end C@L?ia 7

Page 123: MAGENES - 148.206.53.231

i J

Fioyecto Procesatmieiitv Digital d r !magetxs (PDIj 3 <* bAM-I Lic en Somputacion *i (" h j C Pone el Path Hacia las lmagenes *I .............................................................. y I J

';SO+,F+} Litlit Pai-Path Interface Procedtire _Pdi-.PStP, 1rny.lementation &es Li-Vent Lib-Das

Page 124: MAGENES - 148.206.53.231

? 25

Page 125: MAGENES - 148.206.53.231

1. Friedrich M áIVahi, Digital Image Signal Processing, Artech house, Boston and London 1987.

2. Rafael c. Gonzalez and Michael G. Thomason, Syntactic pattern Recogniti,, *rt. an introduction, Addison-Wesley publishing Company, USA 1978

3. IEEE transactions on pattern analysis and machine inteligence, Vol. 11 No. 1 January 1989.

4. IEEE transactions on pattern analysis and machine inteiigence, Vol. 1 I , NrJ. G. June 1989,

5 IEEE transactions on pattern analysis and machine inteligence, Vol. 11, No. 6. July 1990.

6. IEEE transactions on pattern analysis and machine inteligence, Vol. 12. No. 1. January 1990.

7. IEEE transactions on pattern analysis and machine inteligence, Vol 12, No 3 March 1990.

3. IEEE transactions on pattern analysis and machine inteligence. Vol. '!2, Pic. G. JULL 1990,

9. Curso para la UAM-I, filtrado y Reconocimiento de Patrones CINVESTAV IPN México, D.F.

1 C. Microsoft Assembler, programmer's guide, Vlicrosoft corporation , US;, 2 990.

11. Alfred V. Aho, John E. Hopcroft and Jeffre D. ülfman, Estructuras de . d a t ~ ~ ; aigoritmos Addison-Wesley Iberoamericana, México I990