0% found this document useful (0 votes)
42 views28 pages

NTUST CGL2023 02 ImageProcessing-1

Here are the steps to complete the homework assignment: 1. Load the original 24-bit color image using TargaImage::Load_Image() 2. Apply uniform quantization to convert the image from 24-bit to 8-bit color. Quantize the red channel into 8 levels, green into 8 levels, and blue into 4 levels. 3. Apply clustered dithering to the quantized 8-bit image using the given 4x4 threshold mask. Compare each pixel value to the corresponding mask value, and set the pixel to white if it is greater than or equal to the mask value, black otherwise. 4. Save the dithered image using TargaImage::Save_Image().

Uploaded by

ren
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views28 pages

NTUST CGL2023 02 ImageProcessing-1

Here are the steps to complete the homework assignment: 1. Load the original 24-bit color image using TargaImage::Load_Image() 2. Apply uniform quantization to convert the image from 24-bit to 8-bit color. Quantize the red channel into 8 levels, green into 8 levels, and blue into 4 levels. 3. Apply clustered dithering to the quantized 8-bit image using the given 4x4 threshold mask. Compare each pixel value to the corresponding mask value, and set the pixel to white if it is greater than or equal to the mask value, black otherwise. 4. Save the dithered image using TargaImage::Save_Image().

Uploaded by

ren
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Computer Graphics Practice

Image processing 1

Computer Graphics Lab | NTUST CSIE


Overview
• Image Processing
• Raster graphics
• 2D Pixel array
• Transform
• Quantized
• Dithering

Computer Graphics Lab | NTUST CSIE 2


Raster Graphics
Pixel image, also known as a raster image, is an image represented using a pixel array.
• Raster, Pixel, Fragment

• Uniform and Regular Graph


Fixed neighbor number, Fixed relative

Simple

Channel

• Format
jpg, png, tga, hdr…

Color depth (8 bit)

Computer Graphics Lab | NTUST CSIE 3


Raster Graphics
It can be viewed as a three-dimensional array.

Width × Height × channel


height

wid
for example, a 100-pixel wide and 80-pixel high image

h t
would have an array size of 100×80×3.

Since each pixel stores a value between 0 and 255, the total
channel
amount of information in the image would be 100×80×3×8
bits.

Computer Graphics Lab | NTUST CSIE 4


Gray Scale
Luminance (B&W TV)

Computer Graphics Lab | NTUST CSIE 5


Quantized
• Quantization, involved in image processing, is a lossy compression technique achieved by compressing a
range of values to a single quantum value. When the number of discrete symbols in a given stream is
reduced, the stream becomes more compressible.

• Uniform

• Populosity

Computer Graphics Lab | NTUST CSIE 6


Uniform Quantization

0 1 … 31 32 … 63 … 255

¿
¿

{
{
0 1 … 7

Computer Graphics Lab | NTUST CSIE 7


Populosity

uniform quantization
256 256 256

32 32 32

Find 256 most popular colors


1……..256 257……32768

Find the closest color by euclidean (L2) distance in RGB space

Computer Graphics Lab | NTUST CSIE 8


Dithering
Dithering is the attempt by a computer program to approximate a color from a mixture of other colors when
the required color is not available.

Computer Graphics Lab | NTUST CSIE 9


Dithering
• Naive Threshold Dithering
• Brightness Preserving Threshold Dithering
• Random Dithering
• Clustered Dithering
• Floyd-Steinberg Dithering
• Color Floyd-Steinberg Dithering

Computer Graphics Lab | NTUST CSIE 10


Naive Threshold Dithering (1/3)
• Deal with hole image by pixel

• Example: threshold is 127, set value to 255 if pixel value bigger than threshold.
Otherwise set value to 0
10

Computer Graphics Lab | NTUST CSIE 11


Naive Threshold Dithering (2/3)
• Deal with hole image by pixel

• Example: threshold is 127, set value to 255 if pixel value bigger than threshold.
Otherwise set value to 0
10 2 5 8 9 0 0
5 128 255 254 255
0 110 210 220 198
7 90 130 168 157
13 75 60 95 43
Src Dst

Computer Graphics Lab | NTUST CSIE 12


Naive Threshold Dithering (3/3)
• Deal with hole image by pixel

• Example: threshold is 127, set value to 255 if pixel value bigger than threshold.
Otherwise set value to 0
10 2 5 8 9 0 0 0 0 0
5 128 255 254 255 0 255 255 255 255
0 110 210 220 198 0 0 255 255 255
7 90 130 168 157 0 0 255 255 255
0 0 0 0 0
13 75 60 95 43
43
Src Dst

Computer Graphics Lab | NTUST CSIE 13


Brightness Preserving Threshold Dithering

Average gray scale

Get threshold

Computer Graphics Lab | NTUST CSIE 14


Brightness Preserving Threshold Dithering

Computer Graphics Lab | NTUST CSIE 15


Brightness Preserving Threshold Dithering
Brightness Preserving Naïve Threshold

Computer Graphics Lab | NTUST CSIE


Random Dithering
• Add a random amount to each pixel before
thresholding
• Typically add uniformly random amount from [-a,a]
Add random value
• Pure addition of noise to the image
[-0.2,0.2]
• For better results, add better quality noise

• For instance, use Gaussian noise (random values sampled


from a normal distribution)

• Should use same procedure as before for


choosing threshold

• Not good for black and white, but OK for more


colors
• Add a small random color to each pixel before finding the
closest color in the table

Computer Graphics Lab | NTUST CSIE 17


Clustered Dithering

if: img[x][y] >= mask[x%4][y%4]

0.7059 0.3529 0.5882 0.2353


0.0588 0.9412 0.8235 0.4118
0.4706 0.7647 0.8824 0.1176
0.1765 0.5294 0.2941 0.6471

Computer Graphics Lab | NTUST CSIE 18


Floyd-Steinberg Dithering
• Start at one corner and work through image pixel by pixel
• Usually scan top to bottom in a zig-zag

• Threshold each pixel

• Compute the error at that pixel: The difference between what should be there and what you did put
there
• If you made the pixel 0, e = original; if you made it 1, e = original-1

• Propagate error to neighbors by adding some proportion of the error to each unprocessed neighbor
• A mask tells you how to distribute the error

• Easiest to work with floating point image


• Convert all pixels to 0-1 floating point

Computer Graphics Lab | NTUST CSIE 19


Floyd-Steinberg Dithering

Computer Graphics Lab | NTUST CSIE


Floyd-Steinberg Dithering

Computer Graphics Lab | NTUST CSIE 21


Color Floyd-Steinberg Dithering
All the same techniques can be applied, with some modification

Example: 8 bit framebuffer


Set color map by dividing 8 bits into 3,3,2 for RGB

Blue is deemphasized because we see it less well

Dither RGB separately


0 36 73 109 146 182 219 255
Works well with Floyd-Steinberg
0 36 73 109 146 182 219 255
Generally looks good
0 85 170 255
Example is Floyd-Steinberg:
Uniform color table

Error is difference from nearest color in the color table 7/16


Error propagation same as that for greyscale
3/16 5/16 1/16
Each color channel treated independently

Computer Graphics Lab | NTUST CSIE 22


Color Floyd-Steinberg Dithering
Origin Color Floyd Uniform Quant

Computer Graphics Lab | NTUST CSIE


Dithering

• Pixel Operations

• Block Operations

• Neighborhood Operations

Computer Graphics Lab | NTUST CSIE 24


Command
• ScriptHandler.cpp

switch (command)
{
case LOAD:
{
if (pImage)
delete pImage;
char* sFilename = strtok(NULL, c_sWhiteSpace);
bResult = (pImage = TargaImage::Load_Image(sFilename)) != NULL;

if (!bResult)
{
if (!sFilename)
cout << "Unable to load image: " << endl;
else
cout << "Unable to load image: " << sFilename << endl;

bParsed = false;
}// if
break;
}// LOAD

Computer Graphics Lab | NTUST CSIE


Application
• TargaImage.h

Computer Graphics Lab | NTUST CSIE 26


Application
• Image

• RGBA

• 8bit each channel

• Unsigned char (0~255)

Computer Graphics Lab | NTUST CSIE 27


Homework
• 本次作業開始,未按照上傳格式以 0 分計算 !

• Grayscale

• Uniform Quantization
Use the uniform quantization algorithm to convert the current image from a 24 bit color image to an 8 bit color image.

Use 4 shades of blue, 8 shades of red, and 8 shades of green in the quantized image.

• Clustered Dithering
Dither an image to black and white using cluster dithering with the matrix shown below. The image pixels should be
compared to a threshold that depends on the dither matrix below. The pixel should be drawn white if: I[x][y] >=mask[x%4][y
%4]. The matrix is 0.7059 0.3529 0.5882 0.2353
0.0588 0.9412 0.8235 0.4118
0.4706 0.7647 0.8824 0.1176
0.1765 0.5294 0.2941 0.6471
Computer Graphics Lab | NTUST CSIE 28

You might also like