Mostrando entradas con la etiqueta Quantization. Mostrar todas las entradas
Mostrando entradas con la etiqueta Quantization. Mostrar todas las entradas

01 diciembre 2010

Implementación de un cuantizador “midtread” en MATLAB 7.0

La cuantización es el paso necesario para convertir una señal analógica a una digital, cuando se muestrea una señal se convierte del mundo analógico al mundo digital, y es necesario expresarlo en 0s y 1s, dícese bits. Aunque no necesariamente es el proceso de una señal analógica per se, puede ser también, por ejemplo, una imagen que necesita ser representada con una cantidad menor de bits, y por lo consiguiente comprimirla, con pérdidas claro está.

Existen variados tipos de cuantización. El tipo de cuantizador se elige dependiendo de la aplicación en que vaya a ser implementado, esto, de acuerdo a las características de la señal. En este caso se hará un pequeño ejemplo con un cuantizador midtread la grafica siguiente muestra el comportamiento de un cuantizador midtread de 3bits.

cuantización

Figura 1. Características de un cuantizador midtread de 3 bits

El principal uso de este cuantizador es cuando tenemos una señal simétrica en el espectro positivo y negativo, por ejemplo una señal de audio, aunque también se puede aplicar en una imagen, como se muestra en el párrafo siguiente.

En la Figura 1 el eje equis (x) representa la señal a cuantizar y el eje ye (y) es la información ya cuantizada, delta () son los incrementos en los que se va a dividir la señal y esto depende del número de bits que sea el cuantizador, de lo anterior se puede desprender la siguiente tabla:

Código binario Nivel de Cuantización (y) Rango de la señal de entrada (x)

011

-3∆

–3.5∆ <= x < –2.5∆

010

-2∆

–2.5∆ <= x < –1.5∆

001

-1∆

–1.5∆ <= x < –0.5∆

000

0

–0.5∆ <= x < 0

100

0

0 <= x < 0.5∆

101

1∆

0.5∆ <= x < 1.5∆

110

2∆

1.5∆ <= x < 2.5∆

111

3∆

2.5∆ <= x < 3.5∆

La variable delta (∆) puede ser calculada de la siguiente manera

clip_image002

Ora si, vamos a ver el siguiente ejemplo, tenemos la señal de entrada x(n) = 254 254 252 254 255 253 y el rango válido de datos es de 250 a 255, que bien puede ser parte de una imagen ;) .

El primer paso es calcular delta.

clip_image002[4]

Sustituyendo ∆ en la tabla anterior tenemos:

Código binario Nivel de Cuantización (y) Rango de la señal de entrada (x)

011

-3(0.71428) = -2.14284

–2.5 <= x < –1.7857

010

-2(0.71428) = -1.42856

–1.7857 <= x < –1.07142

001

-1(0.71428) = 0.71428

–1.07142 <= x < –0.35714

000

0

–0.35714 <= x < 0

100

0

0 <= x < 0.35714

101

1(0.71428) = 0.71428

0.35714<= x < 1.07142

110

2(0.71428) = 1.42856

1.07142 <= x < 1.7857

111

3(0.71428) = 2.14284

1.7857 <= x < 2.5

Para poder tener los datos de forma como se muestra en la Figura 1, es necesario definir cual es la media de nuestro rango, que en este caso es:

clip_image002[6]

Si restamos a la señal de entrada la media obtenida en el paso anterior tenemos que:

x(n) – µ = 1.5 1.5 -0.5 1.5 2.5 0.5

ahora el siguiente paso es cuantizar cada valor utilizando la tablita arriba descrita…

x(0) = 1.5, cae entre 1.07142 y 1.7857 a lo cual corresponde un valor de cuantización de 1.42856 o sea 110 binario.

x(1) = 1.5, cae entre 1.07142 y 1.7857 a lo cual corresponde un valor de cuantización de 1.42856 o sea 110 binario.

x(2) = –0.5, cae entre –0.35714 y –1.07142 a lo cual corresponde un valor de cuantización de –1.42856 o sea 010 binario.

x(3) = 1.5, cae entre 1.07142 y 1.7857 a lo cual corresponde un valor de cuantización de 1.42856 o sea 110 binario.

x(4) = 2.5, cae entre 1.7857 y 2.5 a lo cual corresponde un valor de cuantización de 2.14284 o sea 111 binario.

x(5) = 0.5 cae entre 0.35714 y 1.07142 a lo cual corresponde un valor de cuantización de 1.42856 o sea 010 binario.

A continuación se presenta el código en MATLAB 7.0 para llevar a cabo esta cuantización:

x = [254 254 252 254 255 253];

bits = 3;
rango_superior = 255;
rango_inferior = 250;

delta = (rango_superior - rango_inferior)/((2^bits)-1)

mu = ((rango_superior - rango_inferior)/2) + rango_inferior

x_centrada = x - mu

x_cuantizada = floor(x_centrada/delta+0.5) * delta

y los resultados son:

delta =

    0.7143

mu =

  252.5000

x_centrada =

    1.5000    1.5000   -0.5000    1.5000    2.5000    0.5000

x_cuantizada =

    1.4286    1.4286   -0.7143    1.4286    2.8571    0.7143

27 febrero 2009

Quantization by Dummies

homersimpson Every time it happens to me, I remember the episode in The Simpsons where Homer wants to get a raise when he was working at Bowlarama, he proposes to Al to triple the business, then you can see Homer reading “Advanced Marketing”, next scene the book is in trash bin and Homer is reading “Basic Marketing”, after that you can see a pile of books in the trash and Homer looking for the word “marketing” at the dictionary…

I had to read an technical article related to Quantization and present an explanation for the Digital Image Processing class in a workshop session. The teacher gave us a list of articles related to quantization and she asked us to choose one of them. The first problem we faced was the availability of the papers, although the university has some kind of subscription with IEEE and ScienceDirect, the number of articles available for us to download was very limited and the date of them was quite old.

While looking at the titles of the papers “the” question was arisen, which article should I choose? First of all looked at the articles that sounded good to me, then I realized that none of them were available from IEEE, and couldn’t connect to ScienceDirect from school. Then I started searching any article from the list available from IEEE was Generalized Scalar Quantizer Design Using Dynamic Programming (bear in mind that if you don’t have a subscription you can’t see the article). The article is three pages long, but I couldn’t get to understand it enough to make a presentation.

I gave up searching the articles from the list and started surfing with Saint Google, I don’t remember the keywords I used to search, but I came up with “Optimal Entropy-Constrained Scalar Quantization of a Uniform Source”. It’s funny because while writing this post I was looking for the link to this file and found that the one of the coauthors of the article, ANDRÁS GYÖRGY,  has a bunch of his papers published listed in his publication's page, are available to download and some of them are about quantization.

After that, troubles has just begun, I started reading the article, and realized that most of the ideas were unclear to me, then I had to go to the books to search for the definition of the term I was stuck with, but while reading the definition I found also some things that for the moment I wasn’t able to understand, besides that I couldn’t found any ‘for dummies’ book about digital image processing, go figure, and it’s obvious there is no such thing. So I was reading in circles, finally, I put some kind of order in my ideas and made a presentation with the concepts I got. Still, it wasn’t enough to be clear the concept proposed in the paper, at least for me.

The best thing that I recall from this exercise is that it helped me to understand that research is not easy, but reading and sharing the little knowledge acquired, is the only way to start learning new things, it opens the mind to a different level, because we can see the work other people involved in the same field is doing, and also get fresh ideas from our peers, remember that feedback is always good and there is no such thing as “constructive nor destructive” critics.

This is I

Blog dedicado a escribir sobre Sistemas Embebidos y el Internet de las Cosas o IoT que le llaman.