Kamis, 11 Juni 2020

Python Code Citra Lat1

latCitraH1
In [5]:
import os
from PIL import Image
import cv2
import numpy as np
import matplotlib.pyplot as plt
#from matplotlib import pyplot as plt
In [6]:
def uk1(img):
    width = int(img.shape[0])
    height = int(img.shape[1])
    return (width ,' x ' , height)

def uk2(img):
    width =len(img[0])
    height = len(img[1])
    return (width ,' x ' , height)

def uk3(img):
    s =len(img)
    print(s)
    return s

def uk4(img):
    s =img.shape()
    print(s)
    return s

def model(img):
    lap=type(img)
    return lap
In [7]:
path = os.getcwd()
print ("Saat ini Anda berada di "+path)
citra=path+'\\garuda1.png'
print ("Citra Uji: "+citra)

img = cv2.imread(citra,0)
print("Ukuran: ",uk1(img))
print("Model: ",model(img))
print("Type: ",type(img))

hist,bins = np.histogram(img.flatten(),256,[0,256])

cdf = hist.cumsum()
cdf_normalized = cdf * hist.max()/ cdf.max()

plt.plot(cdf_normalized, color = 'b')
plt.hist(img.flatten(),256,[0,256], color = 'r')
plt.xlim([0,256])
plt.legend(('cdf','histogram'), loc = 'upper left')
plt.show()
Saat ini Anda berada di C:\Users\USER\_CITRA
Citra Uji: C:\Users\USER\_CITRA\garuda1.png
Ukuran:  (714, ' x ', 714)
Model:  <class 'numpy.ndarray'>
Type:  <class 'numpy.ndarray'>
In [8]:
asli = cv2.imread(citra)
gray = cv2.cvtColor(asli, cv2.COLOR_BGR2GRAY) 
edges = cv2.Canny(gray,100,200)


fig = plt.figure()

plt.subplot(2, 2, 1)
plt.imshow(asli)
plt.title('Citra Asli')

plt.subplot(2, 2, 2)
plt.imshow(gray)
plt.title('Grayscale')

plt.subplot(2, 2, 3)
plt.imshow(edges)
plt.title('Citra Tepi')

plt.subplot(2, 2, 4)
plt.hist(edges)
plt.title('Histogram')

plt.show()
In [9]:
import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('garuda1.jpg',0)
edges = cv2.Canny(img,100,200)

plt.subplot(121),plt.imshow(img,cmap = 'gray')
plt.title('Original Image'), plt.xticks([]), plt.yticks([])

plt.subplot(122),plt.imshow(edges,cmap = 'gray')
plt.title('Edge Image'), plt.xticks([]), plt.yticks([])

plt.show()
In [ ]:
 

Tidak ada komentar:

Posting Komentar