NTUST CGL2023 02 ImageProcessing-1
NTUST CGL2023 02 ImageProcessing-1
Image processing 1
Simple
Channel
• Format
jpg, png, tga, hdr…
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.
• Uniform
• Populosity
0 1 … 31 32 … 63 … 255
¿
¿
{
{
0 1 … 7
uniform quantization
256 256 256
32 32 32
• Example: threshold is 127, set value to 255 if pixel value bigger than threshold.
Otherwise set value to 0
10
• 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
• 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
Get threshold
• 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
• Pixel Operations
• Block Operations
• Neighborhood Operations
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
• RGBA
• 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