You are on page 1of 10

LAPORAN PRAKTIKUM

Pengolahan Citra

Dosen Pengampu : Dedi Irawan, S.Kom, M.Kom.

Disusun Oleh :
Marisko Yudistira : 21430076

PROGRAM STUDI ILMU KOMPUTER


FAKULTAS ILMU KOMPUTER
UNIVERSITAS MUHAMMADIYAH METRO
2022/2023
Instal Python dan OpenCV
1. Kunjungi alamat https://www.python.org/download/

2. Buat Folder baru di drive C, berikan nama foldernya menjadi

3. Pilih Costumesize installation

1
4. Pilih Python311

5. Lakukan upgrade pip

2
6. Tampilan Python

7. Coding pertama
import cv2

image = cv2.imread('doraemon.jpg')
(h, w) = image.shape[:2]

#image[0:cY, 0:cX] = (153, 222, 76)


#cv2.imshow('Gambar manipulasi', image)

#informasi pixel
(b, g, r) = image[0, 0]
print ("Pixel pada (0,0) - red : {}, green : {}, blue :{}". format(r,g,b))

image[0,0] = (255, 0, 0)
(b, g, r) = image[0,0]
print ("Pixel pada (0,0) - red : {}, green : {}, blue : {}". format(r,g,b))

(cX, cY) = (w // 2, h // 2)
kiri_atas = image [0:cY, 0:cX]
kanan_atas = image [0:cY, cX:w]
kanan_bawah = image [cY:h, cX:w]
kiri_bawah = image [cY:h, 0:cX]

cv2.imshow('Kiri Atas', kiri_atas)


cv2.imshow('Kanan Atas', kanan_atas)

3
cv2.imshow('Kanan Bawah', kanan_bawah)
cv2.imshow('Kiri Bawah', kiri_bawah)

#image[0:cY, 0:cX] = (153, 222, 76)


#cv2.imshow('Gambar manipulasi', image)

8. Coding Kedua
import cv2

image = cv2.imread('doraemon.jpg')
(h, w) = image.shape[:2]

#cv2.imshow('gambar asli', image)

#informasi pixel
(b, g, r) = image[0, 0]
print ("Pixel pada (0,0) - red : {}, green : {}, blue : {}". format(r,g,b))

image[0,0] = (255, 0, 0)
(b, g, r) = image[0, 0]
print ("Pixel pada (0,0) - red : {}, green : {}, blue : {}". format(r,g,b))

4
(cX, cY) = (w//2, h//2)
atas = image [0:cY]
bawah = image [cY:h]

cv2.imshow('Atas', atas)
cv2.imshow('Bawah', bawah)

#image[0:cY, 0:cX] = (153, 222, 76)


#cv2.imshow('gambar manipulasi', image)
cv2.waitKey(0)

9. Coding Ketiga
import cv2

image = cv2.imread('doraemon.jpg')
(h, w) = image.shape[:2]

#cv2.imshow('gambar asli', image)

#informasi pixel
(b, g, r) = image[0, 0]
print ("Pixel pada (0,0) - red : {}, green : {}, blue : {}". format(r,g,b))

5
image[0,0] = (255, 0, 0)
(b, g, r) = image[0, 0]
print ("Pixel pada (0,0) - red : {}, green : {}, blue : {}". format(r,g,b))

(cX, cY) = (w//2, h//1)


kiri = image [0:cY, 0:cX]
kanan = image [0:cY, cX:w]

cv2.imshow('Kiri', kiri)
cv2.imshow('Kanan', kanan)

#image[0:cY, 0:cX] = (153, 222, 76)


#cv2.imshow('gambar manipulasi', image)

cv2.waitKey(0)

6
10. Koding Keempat
#import opencv
import cv2

#import numpy
import numpy as np

#import matplotlib

7
from matplotlib import pyplot as plt

#menentukan file gambar yang akan ditampilkan


gambar = cv2.imread('doraemon.jpg')

#tampilkan gambar
cv2 .imshow('image',gambar)

#menampilkan histogram
color = ('g','b','r')
for i,col in enumerate(color):

#cv.calcHisst() digunakan untuk menghitung histogram


histr = cv2.calcHist([gambar],[i],None,[256],[0,256])

#digunakan untuk menampilkan histogram yang telah dihitung


plt.plot(histr,color = col)
plt.xlim([0,256])

plt.show()

11. Koding Kelima


import cv2

image = cv2.imread('doraemon.jpg')
(h, w) = image.shape[:2]

(b, g, r) = image[0, 0]

8
print ("Pixel pada (0,0) - red : {}, blue : {}, green :{}". format(r,b,g))

image[0,0] = (255, 0, 0)
(b, g, r) = image[0,0]
print ("Pixel pada (0,0) - red : {}, blue : {}, green : {}". format(r,b,g))

(cX, cY) = (w // 2, h // 2)
kiri_atas = image [0:cY, 0:cX]
atas = image [0:cY, cX-w//6:cX+w//6]
kanan_atas = image [0:cY, cX:w]
kanan_bawah = image [cY:h, cX:w]
bawah = image [cY:, cX-w//6:cX+w//6]
kiri_bawah = image [cY:h, 0:cX]

cv2.imshow('Kiri Atas', kiri_atas)


cv2.imshow('atas', atas)
cv2.imshow('Kanan Atas', kanan_atas)
cv2.imshow('Kanan Bawah', kanan_bawah)
cv2.imshow('bawah', bawah)
cv2.imshow('Kiri Bawah', kiri_bawah)

cv2.waitKey(0)

You might also like