1-Soshum-M7-Image-Processing - Ipynb - Colab
1-Soshum-M7-Image-Processing - Ipynb - Colab
ipynb - Colab
Numpy is an array manipulation library, used for linear algebra, Fourier transform, and random number capabilities.
Pandas is a library for data manipulation and data analysis.
CV2 is a library for computer vision tasks.
Skimage is a library which supports image processing applications on python.
Matplotlib is a library which generates figures and provides graphical user interface toolkit.
import numpy as np
import pandas as pd
import cv2 as cv
from google.colab.patches import cv2_imshow # for image display
from skimage import io
from PIL import Image
import matplotlib.pylab as plt
RGB? Red Green Blue. RGB adalah channel warna standar yang digunakan oleh sebuah layar/gambar berwarna.
https://colab.research.google.com/drive/1LhCBqGP-0lXVkZuAOn80tMCcf6kFFa0L#scrollTo=XUMXfKr5gMl9&printMode=true 1/9
05/05/25, 15.19 1-Soshum-M7-Image-Processing.ipynb - Colab
Place Kitten - use the base Place Kitten URL followed by a width and height separated by backslashes ''/''. For example, use the URL
https://placekitten.com/500/300 to fetch a cat image with a width of 500px and height of 300px.
NC State University Libraries Special Collections - browse the site to find an image thumbnail. Right-click on the thumbnail and select "Copy
Image Address". The address will look like this: https://iiif.lib.ncsu.edu/iiif/0051230/square/300,/0/default.jpg . Replace the word
"square" with the word "full" and replace "300" with "800" to access the full image at a width of 800px.
Google Image search - search for an image. Left-click one of the returned images, then right-click on the full image, and then select "Copy
Image Address".
## Silahkan lakukan langkah seperti diatas, dengan gambar Anda sendiri dengan menghapus tanda #
## pada kode dibawah ini dan mengisi url dari gambar yang akan Anda gunakan.
# url =
# myImg = io.imread(url)
# cv2_imshow(cv.cvtColor(myImg, cv.COLOR_BGR2RGB))
https://colab.research.google.com/drive/1LhCBqGP-0lXVkZuAOn80tMCcf6kFFa0L#scrollTo=XUMXfKr5gMl9&printMode=true 2/9
05/05/25, 15.19 1-Soshum-M7-Image-Processing.ipynb - Colab
print(image.shape[1])
# Check the number of channels of the image
print(image.shape[2])
uint8
571
800
3
Terkadang Anda ingin meningkatkan kontras pada gambar atau memperluas kontras di wilayah tertentu sambil mengorbankan detail dalam
warna yang tidak terlalu bervariasi, atau tidak penting. Alat yang baik untuk menemukan wilayah yang menarik adalah dengan menggunakan
histogram gambar. Untuk membuat histogram dari data gambar kita, kita menggunakan fungsi matplot.pylab hist ().
Menampilkan histogram dari channel R, G, B. Kita dapat mengamati bahwa saluran hijau memiliki banyak pixel pada nilai 255 dimana nilai
255 ini mewakili warna putih pada gambar
color = ('b','g','r')
for i,col in enumerate(color):
histr = cv.calcHist([image],[i],None,[256],[0,256])
plt.plot(histr,color = col)
plt.xlim([0,256])
plt.show()
https://colab.research.google.com/drive/1LhCBqGP-0lXVkZuAOn80tMCcf6kFFa0L#scrollTo=XUMXfKr5gMl9&printMode=true 3/9
05/05/25, 15.19 1-Soshum-M7-Image-Processing.ipynb - Colab
# Plot the histogram of the gray image. We could observe that the frequency of
# the image hist has decreased ~ 1/3 of the histogram of color image
plt.hist(gray_image.ravel(),bins = 256, range = [0, 256])
plt.show()
keyboard_arrow_down TODO # 2: DISPLAY THE GRAYSCALE OF YOUR COLOR IMAGE AND GENERATE HISTOGRAM
## Silahkan lakukan langkah seperti diatas, dengan gambar Anda sendiri dengan menghapus tanda #
## pada kode dibawah ini
<matplotlib.contour.QuadContourSet at 0x7b5e7efc0d90>
<matplotlib.image.AxesImage at 0x7b5e7ee94750>
## Silahkan lakukan langkah seperti diatas, dengan gambar Anda sendiri dengan menghapus tanda #
## pada kode dibawah ini
# plt.contour(myGrayImg)
Bagian ini memberikan beberapa contoh melakukan transformasi matematis pada gambar grayscale
# This is an inverse operation of the grayscale image, you could see that the
# bright pixels become dark, and the dark pixels become bright
im2 = 255 - gray_image
cv2_imshow(im2)
https://colab.research.google.com/drive/1LhCBqGP-0lXVkZuAOn80tMCcf6kFFa0L#scrollTo=XUMXfKr5gMl9&printMode=true 5/9
05/05/25, 15.19 1-Soshum-M7-Image-Processing.ipynb - Colab
https://colab.research.google.com/drive/1LhCBqGP-0lXVkZuAOn80tMCcf6kFFa0L#scrollTo=XUMXfKr5gMl9&printMode=true 6/9
05/05/25, 15.19 1-Soshum-M7-Image-Processing.ipynb - Colab
This section demonstrates histogram equalization on a dark image. This transform flattens the gray-level histogram so that all intensities are
as equally common as possible. The transform function is a cumulative distribution function (cdf) of the pixel values in the image
(normalized to map the range of pixel values to the desired range). This example uses image 4 (im4).
https://colab.research.google.com/drive/1LhCBqGP-0lXVkZuAOn80tMCcf6kFFa0L#scrollTo=XUMXfKr5gMl9&printMode=true 7/9
05/05/25, 15.19 1-Soshum-M7-Image-Processing.ipynb - Colab
# Extra: try to visualize the histogram of the image after histogram equalization
# Before histogram equalization
plt.hist(im4.ravel(),bins = 256, range = [0, 256])
plt.show()
https://colab.research.google.com/drive/1LhCBqGP-0lXVkZuAOn80tMCcf6kFFa0L#scrollTo=XUMXfKr5gMl9&printMode=true 8/9
05/05/25, 15.19 1-Soshum-M7-Image-Processing.ipynb - Colab
https://colab.research.google.com/drive/1LhCBqGP-0lXVkZuAOn80tMCcf6kFFa0L#scrollTo=XUMXfKr5gMl9&printMode=true 9/9