• Tidak ada hasil yang ditemukan

PENGOLAHAN CITRA Ch.4 M E N G O L A H C I T R A M E N J A D I N E G A T I V E Bayu Pratama RN [ ]

N/A
N/A
Protected

Academic year: 2021

Membagikan "PENGOLAHAN CITRA Ch.4 M E N G O L A H C I T R A M E N J A D I N E G A T I V E Bayu Pratama RN [ ]"

Copied!
11
0
0

Teks penuh

(1)

PENGOLAHAN CITRA – Ch.4

M E N G O L A H C I T R A M E N J A D I N E G A T I V E

Bayu Pratama RN [ [email protected] ]

Tujuan Praktikum

- Mengetahui cara membuat program yang mengubah image berwarna ke negative nya

INFORMASI

Pada praktikum ke-4 ini melanjutkan file yang telah kalian buat dari praktikum ke-2

. Sebelumnya lakukan kopi

folder proyek yang kalian buat dari praktikum ke-2 (LatihanPengcit2) ke folder LatihanPengcit4. Hal ini karena

LatihanPengcit2 nantinya akan digunakan lagi. (Jika kalian ingin membuat dari awal juga tidak apa-apa).

PEMBUATAN CITRA NEGATIF

Suatu citra dapat dibuat negatif atau berkebalikan. Pada citra 1 bit yang hanya memiliki warna hitam dan

putih, proses membuat negatif dapat dilakukan dengan mudah, yaitu membalik warna putih menjadi hitam,

dan warna hitam menjadi putih. Proses diatas dapat digambarkan sebagai berikut

1

1

1

0

0

0

0

0

0

1

1

1

1

0

1

0

1

0

Gambar sebelah kiri adalah citra berukuran 3x3 yang masih asli. Sementara yang sebelah kanan adalah citra

yang telah dibuat negatif. Ada dua cara untuk membuat negatif, yaitu dengan operasi biner NOT

Warna2 = NOT Warna1

Atau dapat dengan melakukan pengurangan

Warna2 = 255 – Warna1

Untuk citra 24bit RGB, proses pembuatan citra negatif dilakukan sendiri-sendiri pada komponen Red, Green,

dan Blue. Algoritmanya adalah sebagai berikut

For I:=0 to ImageWidth -1

For J:=0 to ImageHeight -1

Color := GetPixel( I , J ) ; // mengambil pixel pada koordinat (I , J)

Color.Red := 255 - Color.Red ;

Color.Green := 255 - Color.Green;

Color.Blue := 255 - Color.Blue;

SetPixel( I , J , Color) ; // mengubah pixel pada koordinat (I , J)

End For

(2)

Di bawah ini adalah perbandingan citra sebelum dan sesudah manipulasi negatif

Sebelum

Sesudah

Histogram Red (Sebelum)

Histogram Red

(3)

Histogram Blue (Sebelum)

Histogram Blue

Image yang telah diubah menjadi negative, bisa dilihat bentuk histogramnya, bandingkan sebelum dan

sesudah, bentuknya akan berkebalikan.

BAGAIMANA MEMBUAT PROGRAM YANG BISA MENGUBAH IMAGE KE NEGATIVE?

Bagian ini melanjutkan source code yang telah dibuat dari praktikum ke-2.

1. Salin folder proyek kalian dan beri nama LatihanPengcit4.

2. Selanjutnya, buka folder baru tersebut. Untuk membuka proyek, kalian bisa melakukan double klik

pada file .sln atau file .csproj yang iconnya seperti di bawah ini

3. Proyek anda akan terbuka. Tugas anda selanjutnya adalah menambahkan sebuah Button ke dalam

Form dengan property sebagai berikut

Nama

Tipe

Property Name

Property Value

button3

Button

Text

NEGATIVE

(4)

4.

Pada Form Designer, double klik tombol “NEGATIVE”

5. Selanjutnya, anda akan berada dalam modus Source Code. Visual Studio akan secara otomatis

men-generate method yang sesuai dengan Event “Click” dari button1, yaitu button3_Click

(5)

6. Kemudian Isikan potongan kode di bawah ini

7. Simpan proyek anda.

8. Jalankan program dengan menekan F5

9. Coba Anda tekan tombol “LOAD”, lalu anda pilih file gambar

(6)

11. Berikut ini adalah contoh screenshot nya jika anda berhasil

12. Silakan anda coba coba modifikasi sendiri tampilannya agar sesuai selera anda :P

Penjelasan :

Program di atas merupakan program sederhana untuk mengubah image warna ke negative. Setelah

pengguna me-load image dan kemudian menekan tombol “NEGATIVE”, maka code di dalam method

“button3_Click” dijalankan. Proses tersebut sama dengan algoritma yang telah ditulis di atas.

Color c = bm.GetPixel( x, y );

Pada code diatas, program mengambil pixel pada koordinat tertentu. Pixel tersebut merubakan suatu object

dari class Color, dimana class Color memiliki property R,G, dan B.

Untuk membuat negatif, kita hanya perlu rumus berikut

Color c2 = Color.FromArgb( c.A, 255 – c.R, 255 – c.G, 255 – c.B );

Jika sudah, hasil penghitungan kita ganti warna pixel dengan warna yang baru yang sudah Negative.

bm.SetPixel( x, y, c2 );

(7)

REFERENSI CLASS DAN METHOD YANG SERING DIGUNAKAN

Namespace :

System.Drawing

Class :

Bitmap

Turunan dari Class :

Image

(Abstract Class)

public sealed class Bitmap : System.Drawing.Image Member of System.Drawing

Summary:

Encapsulates a GDI+ bitmap, which consists of the pixel data for a graphics image and its attributes. A System.Drawing.Bitmap is an object used to work with images defined by pixel data.

Constructor :

public Bitmap(string filename) Member of System.Drawing.Bitmap Summary:

Initializes a new instance of the System.Drawing.Bitmap class from the specified file. Parameters:

filename: The name of the bitmap file. public Bitmap(int width, int height) Member of System.Drawing.Bitmap Summary:

Initializes a new instance of the System.Drawing.Bitmap class with the specified size. Parameters:

width: The width, in pixels, of the new System.Drawing.Bitmap. height: The height, in pixels, of the new System.Drawing.Bitmap.

Method :

public static System.Drawing.Image FromFile(string filename) Member of System.Drawing.Image

Summary:

Creates an System.Drawing.Image from the specified file. Parameters:

filename: A string that contains the name of the file from which to create the System.Drawing.Image. Returns:

The System.Drawing.Image this method creates.

public System.Drawing.Color GetPixel(int x, int y) Member of System.Drawing.Bitmap

Summary:

(8)

x: The x-coordinate of the pixel to retrieve. y: The y-coordinate of the pixel to retrieve. Returns:

A System.Drawing.Color structure that represents the color of the specified pixel.

public void Save(string filename) Member of System.Drawing.Image Summary:

Saves this System.Drawing.Image to the specified file or stream. Parameters:

filename: A string that contains the name of the file to which to save this System.Drawing.Image. public void SetPixel(int x, int y, System.Drawing.Color color)

Member of System.Drawing.Bitmap Summary:

Sets the color of the specified pixel in this System.Drawing.Bitmap. Parameters:

x: The x-coordinate of the pixel to set. y: The y-coordinate of the pixel to set.

color: A System.Drawing.Color structure that represents the color to assign to the specified pixel.

Property :

public int Height { get; }

Member of System.Drawing.Image Summary:

Gets the height, in pixels, of this System.Drawing.Image. Returns:

The height, in pixels, of this System.Drawing.Image. public float HorizontalResolution { get; } Member of System.Drawing.Image Summary:

Gets the horizontal resolution, in pixels per inch, of this System.Drawing.Image. Returns:

The horizontal resolution, in pixels per inch, of this System.Drawing.Image. public System.Drawing.Imaging.PixelFormat PixelFormat { get; } Member of System.Drawing.Image

(9)

public System.Drawing.Imaging.ImageFormat RawFormat { get; } Member of System.Drawing.Image

Summary:

Gets the file format of this System.Drawing.Image. Returns:

The System.Drawing.Imaging.ImageFormat that represents the file format of this System.Drawing.Image. public float VerticalResolution { get; }

Member of System.Drawing.Image Summary:

Gets the vertical resolution, in pixels per inch, of this System.Drawing.Image. Returns:

The vertical resolution, in pixels per inch, of this System.Drawing.Image. public int Width { get; }

Member of System.Drawing.Image Summary:

Gets the width, in pixels, of this System.Drawing.Image. Returns:

The width, in pixels, of this System.Drawing.Image.

Namespace :

System.Drawing

Struct :

Color

Turunan dari Class :

ValueType

(Abstract Class)

public struct Color

Member of System.Drawing Summary:

Represents an ARGB (alpha, red, green, blue) color.

Constructor :

public Color()

Member of System.Drawing.Color

Method :

public static System.Drawing.Color FromArgb(int red, int green, int blue) Member of System.Drawing.Color

Summary:

Creates a System.Drawing.Color structure from the specified 8-bit color values (red, green, and blue). The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the

(10)

Parameters:

red: The red component value for the new System.Drawing.Color. Valid values are 0 through 255. green: The green component value for the new System.Drawing.Color. Valid values are 0 through 255. blue: The blue component value for the new System.Drawing.Color. Valid values are 0 through 255. Returns:

The System.Drawing.Color that this method creates.

public static System.Drawing.Color FromArgb(int alpha, System.Drawing.Color baseColor) Member of System.Drawing.Color

Summary:

Creates a System.Drawing.Color structure from the specified System.Drawing.Color structure, but with the new specified alpha value. Although this method allows a 32-bit value to be passed for the alpha value, the value is limited to 8 bits.

Parameters:

alpha: The alpha value for the new System.Drawing.Color. Valid values are 0 through 255. baseColor: The System.Drawing.Color from which to create the new System.Drawing.Color. Returns:

The System.Drawing.Color that this method creates.

public static System.Drawing.Color FromArgb(int alpha, int red, int green, int blue) Member of System.Drawing.Color

Summary:

Creates a System.Drawing.Color structure from the four ARGB component (alpha, red, green, and blue) values.

Although this method allows a 32-bit value to be passed for each component, the value of each component is limited to 8 bits.

Parameters:

alpha: The alpha component. Valid values are 0 through 255. red: The red component. Valid values are 0 through 255. green: The green component. Valid values are 0 through 255. blue: The blue component. Valid values are 0 through 255. Returns:

The System.Drawing.Color that this method creates. public float GetBrightness()

Member of System.Drawing.Color Summary:

Gets the hue-saturation-brightness (HSB) brightness value for this System.Drawing.Color structure. Returns:

The brightness of this System.Drawing.Color. The brightness ranges from 0.0 through 1.0, where 0.0 represents black and 1.0 represents white.

public float GetHue()

(11)

The hue, in degrees, of this System.Drawing.Color. The hue is measured in degrees, ranging from 0.0 through 360.0, in HSB color space.

public float GetSaturation()

Member of System.Drawing.Color Summary:

Gets the hue-saturation-brightness (HSB) saturation value for this System.Drawing.Color structure. Returns:

The saturation of this System.Drawing.Color. The saturation ranges from 0.0 through 1.0, where 0.0 is grayscale and 1.0 is the most saturated.

Property :

public byte A { get; }

Member of System.Drawing.Color Summary:

Gets the alpha component value of this System.Drawing.Color structure. Returns:

The alpha component value of this System.Drawing.Color. public byte B { get; }

Member of System.Drawing.Color Summary:

Gets the blue component value of this System.Drawing.Color structure. Returns:

The blue component value of this System.Drawing.Color. public byte G { get; }

Member of System.Drawing.Color Summary:

Gets the green component value of this System.Drawing.Color structure. Returns:

The green component value of this System.Drawing.Color. public byte R { get; }

Member of System.Drawing.Color Summary:

Gets the red component value of this System.Drawing.Color structure. Returns:

Gambar

Gambar sebelah kiri adalah citra berukuran 3x3 yang masih asli. Sementara yang sebelah kanan adalah citra  yang telah dibuat negatif

Referensi

Dokumen terkait

Nilai koefisien korelasi karakteristik pemukim menunjukan bahwa beberapa peubah persepsi pemukim seperti: (1) keuntungan yang didapatkan dengan bermukim di bantaran

Usaha-usaha dan penelitian untuk memperoleh varietas unggul dapat ditempuh dengan beberapa cara yaitu (a) introduksi atau mendatangkan varietas/bahan seleksi dari luar negeri,

Melalui penerapan sistem data warehouse dapat memberikan dampak positif bagi perusahaan, diantaranya proses analisis ataupun pengelolaan informasi berdasarkan data

Instrumen Pemetaan MUTU PAUDNI Lembaga dan Program Pendidikan Anak Usia Dini (PAUD) yang dilaksanakan SKB. SKB menyerahkan data dan laporan pelaksanaan kepada BP-PAUDNI Regional IV

Khususnya pada DAS Siak di Perawang melalui analisis parameter mikrobiologi meliputi: total bakteri, angka lempeng total jamur, Coliform, serta ada tidaknya kontaminasi

Perusahaan dengan likuiditas tinggi akan memiliki risiko yang relatif kecil sehingga kreditur merasa yakin dalam memberikan pinjaman kepada perusahaan dan investor akan

Adapun tujuan dari distribusi fisik adalah memindahkan produk dalam jumlah tepat, pada waktu yang tepat, dan pada tempat yang tepat pula dan

Dynamically Allocated: Maksud dari jenis ini adalah Hard disk Virtual yang akan digunakan oleh Ubuntu nantinya, semakin lama semakin besar, jika kamu menambahkan data