0% found this document useful (0 votes)
53 views2 pages

Rangkuman Pemrograman Citra Digital

The document contains code for performing several image processing techniques on bitmaps, including: 1. Converting an image to grayscale by averaging the red, green, and blue pixel values. 2. Applying brightness adjustment by increasing or decreasing the red, green, and blue values of each pixel. 3. Applying Gaussian noise by randomly adjusting some pixel values using a Gaussian distribution around the original value. 4. Applying salt and pepper noise by randomly setting some pixel values to white (255) or black (0).

Uploaded by

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

Rangkuman Pemrograman Citra Digital

The document contains code for performing several image processing techniques on bitmaps, including: 1. Converting an image to grayscale by averaging the red, green, and blue pixel values. 2. Applying brightness adjustment by increasing or decreasing the red, green, and blue values of each pixel. 3. Applying Gaussian noise by randomly adjusting some pixel values using a Gaussian distribution around the original value. 4. Applying salt and pepper noise by randomly setting some pixel values to white (255) or black (0).

Uploaded by

yser bang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Bitmap obj1; Color tmp = obj1.

GetPixel(x,y);
Bitmap obj2; int red = tmp.R;
int green = tmp.G;
Openfiledialog: int blue = tmp.B;
int xg = (int) ((red + green + blue) / 3);
DialogResult D = [Link](); Color wb = [Link](xg, xg, xg);
if (D == [Link]) { [Link](x,y,wb);
obj1 = new Bitmap([Link]); }
}
[Link] = obj1; [Link] = obj1;
}

Brightness: Filter 4 Node:

Bitmap obj1 = new Bitmap([Link]); float[] a = new float[5];


Bitmap obj2 = new Bitmap([Link]); a[0] = (float)0.2; //tengah
int r, g, b; a[1] = (float)0.2;
Color c; a[2] = (float)0.2;
a[3] = (float)0.2;
int val = (int)Convert.ToInt16([Link]); a[4] = (float)0.2;

for (int i = 0; i < [Link];i++) obj2 = new Bitmap(obj1);


{
for (int j = 0; j < [Link];j++) for (int x = 1; x < [Link] - 1; x++)
{ {
c = [Link](i, j); for (int y = 1; y < [Link] - 1; y++)
r = c.R + val; {
g = c.G + val; Color w1 = [Link](x - 1, y);
b = c.B + val; Color w2 = [Link](x, y - 1);
if (r > 255) { r = 255; } else { r = r; } Color w3 = [Link](x + 1, y);
if (g > 255) { g = 255; } else { g = g; } Color w4 = [Link](x, y + 1);
if (b > 255) { b = 255; } else { b = b; } Color tmp = [Link](x, y);
if (r < 0) { r = 0; } else { r = r; } int x1 = w1.R;
if (g < 0) { g = 0; } else { g = g; } int x2 = w2.R;
if (b < 0) { b = 0; } else { b = b; } int x3 = w3.R;
[Link](i, j, [Link](r, g, b)); int x4 = w4.R;
} int xg = tmp.R;
} int xb = (int)(a[0] * xg);
[Link] = obj1; xb = (int)(xb + a[1] * x1 + a[2] * x2 + a[3] * x3
} + a[4] * x4);
if (xb < 0) { xb = 0; }
Histogram: if (xb > 255) { xb = 255; }
Color wb = [Link](xb, xb, xb);
float[] h = new float[256]; [Link](x, y, wb);
int i; }
for (i = 0; i < 256; i++) { h[i] = 0; } }
for (int x = 0; x < [Link]; x++) [Link] = obj1;
{ }
for (int y = 0; y < [Link]; y++)
{ Filter 8 Node:
Color xs = [Link](x, y);
//int xg = xs.G; float[] a = new float[10];
int xg = (int)((xs.R * 0.299) + (xs.G * 0.587) + a[0] = (float)0.1;
(xs.B * 0.114)); a[1] = (float)0.1;
h[xg] = h[xg] + 1; a[2] = (float)0.1;
} a[3] = (float)0.1;
} a[4] = (float)0.1;
a[5] = (float)0.2; //tengah
for (i = 0; i < 256; i++) a[6] = (float)0.1;
{ a[7] = (float)0.1;
[Link]["Series1"].[Link](i, h[i]); a[8] = (float)0.1;
} a[9] = (float)0.1;
obj2 = new Bitmap(obj1);
GRAYSCALE: for (int x = 1; x < [Link] - 1; x++) {
for (int y = 1; y < [Link] -1; y++) {
for (int x = 0; x < [Link];x++)
{ Color w1 = [Link](x-1,y-1);
for (int y = 0; y < [Link];y++) Color w2 = [Link](x-1,y);
{ Color w3 = [Link](x-1,y+1);
Color w4 = [Link](x,y-1); Color wb = [Link](xb, xb, xb);
Color w5 = [Link](x, y); //tengah [Link](x, y, wb);
Color w6 = [Link](x,y+1);
Color w7 = [Link](x+1,y-1); }
Color w8 = [Link](x+1,y); }
Color w9 = [Link](x+1,y+1); [Link] = obj1;

int x1 = w1.R;
int x2 = w2.R;
int x3 = w3.R;
int x4 = w4.R;
int x5 = w5.R;
int x6 = w6.R;
int x7 = w7.R;
int x8 = w8.R;
int x9 = w9.R;
int xb = (int)(a[1] * x1 + a[2] * x2 + a[3] * x3
+ a[4] * x4 + a[5] * x5 + a[6] * x6 + a[7] * x7 +
a[8] * x8 + a[9] * x9);
xb = (int)(xb + a[4] * x4 + a[5] * x5 + a[6] *
x6);
xb = (int)(xb + a[7] * x7 + a[8] * x8 + a[9] *
x9);

if (xb > 255) { xb = 255; }


if (xb < 0) { xb = 0; }
Color wb = [Link](xb, xb, xb);
[Link](x, y, wb);
}
[Link] = obj1;

Noise Gaussian:

obj1 = new Bitmap(obj1);


Random r = new Random();
for (int x = 0; x < [Link]; x++) {
for (int y = 0; y < [Link]; y++) {
Color w = [Link](x, y);
int xg = w.R;
int xb = xg;
int nr = [Link](0, 100);
if (nr < 20)
{
int ns = [Link](0, 256) - 128;
xb = (int)(xg + ns);
if (xb < 0) xb = -xb;
if (xb > 255) xb = 255;

}
Color wb = [Link](xb, xb, xb);
[Link](x, y, wb);
}
}
[Link] = obj1;

salt & Pepper:

obj1 = new Bitmap(obj1);


Random r = new Random();
for (int x = 0; x < [Link]; x++)
{
for (int y = 0; y < [Link]; y++)
{
Color w = [Link](x, y);
int xg = w.R;
int xb = xg;
int nr = [Link](0, 100);
if (nr < 20) xb = 255;

You might also like