Histograms- HPP. What is homogeneous? Homogeneous point process treats all pixels the same. p'=f(p);...

Post on 11-Jan-2016

215 views 0 download

transcript

Histograms-

HPP

What is homogeneous?

• Homogeneous point process treats all pixels the same.

• p'=f(p); // homogeneous point processing does not care about pixel location.

• isomorphic pixel mapping.

Homogeneous Point Processing

• Every point is treated the same

• Input size of image is same as output size

• Good application of statistics!

• input image shape is the same as the output image shape.

Image processing• An image processing operation typically

defines a new image g in terms of an existing image f.

You need a function!

• A function has a single possible output value for any unique input value.

• A relation can have two outputs for a given input.

• For example x**2+y**2=r**2 is a relation.

• y=sqrt(x*x+r*r); //take only the + part and you have a function.

Mapping a pixel has many applications

• Brightening an image

• Improving the contrast

• Coloring the image.

• histogram equalization

• converting to a new color space.

How do we implements HPP?

• Standards for HPP base on an INTERFACE.

• The standardization of the filter into interface allows for polymorphism.

Point Processing

• The simplest kind of range transformations are these independent of position x,y:

• g = t(f)

How do we form such an interface?

• java.awt has RGBImageFilter interface

• It requires that you implement

public int filterRGB(int x, int y, int rgb);

1. Unpack the rgb int

2. Do the HPP

3. repack the int and return the value.

How do we unpack our RGB ints?

let RGB=0x7FDEAD50

int a = rgb &0xFF000000>>24;

int r = rgb &0x00FF0000 >>16;

int g = rgb &0x0000FF00 >> 8;

int b = rgb &0x000000FF;

int r1 = getRed(r,g,b);int g1=getGreen(r,g,b);

int b1 = getBlue(r,g,b);

return 0xFF000000 | (r1 << 16) | (g1<<8) | b1;

Adapter Pattern

• Adapter Pattern take one interface and maps to a new interface.

• public interface HppFilterInterface {

• public short getR(int r);

• public short getG(int g);

• public short getB(int b);

• }

InvertFilter

• public class InvertFilter• implements HppFilterInterface {• public short getR(int r) {• return invert(r);• }

• public short getG(int g) {• return invert(g);• }

• public short getB(int b) {• return invert(b);• }

Invert

• private short invert(int v) {

• if (v < 0) return 0;

• if (v > 255) return 255;

• return (short) (255 - v);

• }

Two kinds of methods for altering an image

• The direct methods

• The indirect methods.

• The direct methods employ a mapping function,

• Mapping functions are applied to the color planes.

Two kinds of methods for altering an image

• First we do the direct methods….

PMF

• Add the total number of pixels of a particular value

• Divide by the total number of pixelsValuePMF

0 32/64128 16/64255 16/64

Rules of Prob.

• Sum of all probs=1

• CMF is sum of all values up to a point.

ValuePMF CMF0 32/64 0.5

128 16/64 0.75255 16/64 1

PV(a)

In Prob…Cont vs. Discrete

• PMF – discrete but PDF are Continuous

• CMF – discrete by CDF are continuous

• Example: Toss a coin – discrete

• Example: Temp. Time, space

• CMF uses a discrete summation (for-loop)

• CDF uses an integral

• discrete means quantized

Histogram Computations

histArray = new double[256]; for (int i=0; i<width; i++) for (int j=0; j < height; j++) histArray[plane[i][j] & 0xFF]++;// what happens if you have 24 bit color images?

Normalization of PMF

double max = 0.0; for(int i=0; i<256; i++) if (histArray[i] > max) max = histArray[i]; // Normalize for(int i=0; i<256; i++) histArray[i] = (histArray[i] / max);

The Histogram of the Image

Summary of Histogram

package gui; public class Histogram extends ClosableFrame { public double[] getPMF() public double[] getCMF() public void printPMF() public void show() public Histogram(short plane[][], String title) public void paint(Graphics g) }

Linear Map and Sample Image

LUT implementation

• In theory, lut is easy:– outputColor = f(inputColor)– F(x) is an lut.– What happens if x ranges from 0 to 2**24?

Negating an Image

Implementation

private short invert(int v) { if (v < 0) return 0; if (v > 255) return 255; return (short) (255 - v); }

HppFilterInterface

• public short getR(int r);

• public short getG(int g);

• public short getB(int b);

What is thresholding?

• Requanitze an image.

• for example:– given an image with 256 grays– find an image with only 2 grays

• How do I know which pixels are black and which are white?– if (v < thresh) v = 0, else v = 255;

Two kinds of methods for altering an image

• The direct methods

• The indirect methods.

• The direct methods employ a mapping function,

• Mapping functions are applied to the color planes.

Indirect Methods

• The indirect method use statistical properties

Two Kinds of Indirect Methods:

• adaptive and nonadaptive

Basic Point Processing

Computing Averages

r 1N

rii1

N

getRBar ();

g 1

Ngi

i1

N

getGBar ();

b 1

Nbi

i1

N

getBBar ();

Image Enhancement

Contrast Streching

Power law and image processing

f (vij ) 255vij

255

pow

1.5 exponent=darkening

Power-law transformations

Gamma Correction

Washed out images can result

Changing Brightness and Contrast

vij' cv ij b

c contrast

b brightness

Linear eq and histogramLUT

-50

0

50

100

150

200

250

300

0

19 38 57 76 95 114

133

152

171

190

209

228

247

Brightening and image

Computing parameters automatically

D Dmax Dmin

where

Dmin minumum value that can be displayed and

Dmax maximum value that can be displayed

Darkening Image

Darkening and the Histogram

Implementing the power xform

public void powImage(double p) { for (int x=0; x < width; x++) for (int y=0; y < height; y++) { r[x][y] = (short) (255 * Math.pow((r[x][y]/255.0),p)); g[x][y] = (short) (255 * Math.pow((g[x][y]/255.0),p)); b[x][y] = (short) (255 * Math.pow((b[x][y]/255.0),p)); } short2Image();}

UNAHE

The CMF

0

50

100

150

200

2500 50

100

150

200

250

Adaptive Equalization

Histogram an AUHE

LUT Implementation

package gui; public class TransformTable { public TransformTable(int size) public short[] getLut() public void setLut(short lut[]) public void print() }