Pengolahan Citra Biner

 Deteksi Tepi

import numpy as np

import matplotlib.pyplot as plt

 

from skimage import filters

from skimage.data import camera

from skimage.util import compare_images

 

 

image = camera()

edge_roberts = filters.roberts(image)

edge_sobel = filters.sobel(image)

 

fig, axes = plt.subplots(ncols=2, sharex=True, sharey=True,

                         figsize=(8, 4))

 

axes[0].imshow(edge_roberts, cmap=plt.cm.gray)

axes[0].set_title('Roberts Edge Detection')

 

axes[1].imshow(edge_sobel, cmap=plt.cm.gray)

axes[1].set_title('Sobel Edge Detection')

 

for ax in axes:

    ax.axis('off')

 

plt.tight_layout()

plt.show()


Active_contour

import numpy as np

import matplotlib.pyplot as plt

from skimage.color import rgb2gray

from skimage import data

from skimage.filters import gaussian

from skimage.segmentation import active_contour

img = data.text()

 

r = np.linspace(136, 50, 100)

c = np.linspace(5, 424, 100)

init = np.array([r, c]).T

 

snake = active_contour(gaussian(img, 1), init, boundary_condition='fixed',

                       alpha=0.1, beta=1.0, w_line=-5, w_edge=0, gamma=0.1)

 

fig, ax = plt.subplots(figsize=(9, 5))

ax.imshow(img, cmap=plt.cm.gray)

ax.plot(init[:, 1], init[:, 0], '--r', lw=3)

ax.plot(snake[:, 1], snake[:, 0], '-b', lw=3)

ax.set_xticks([]), ax.set_yticks([])

ax.axis([0, img.shape[1], img.shape[0], 0])

 

plt.show()



Gaussian Noise

import numpy as np

import matplotlib.pyplot as plt

import skimage

import skimage.color as skic

import skimage.filters as skif

import skimage.data as skid

import skimage.util as sku

%matplotlib inline

 

def show(img):

    fig, ax = plt.subplots(1, 1, figsize=(8, 8))

    ax.imshow(img, cmap=plt.cm.gray)

    ax.set_axis_off()

    plt.show()

 

img = skic.rgb2gray(skid.astronaut())

show(img)

 


show(skif.gaussian(img, 5.))

 


sobimg = skif.sobel(img)

show(sobimg)

 


from ipywidgets import widgets

 

@widgets.interact(x=(0.01, .2, .005))

def edge(x):

    show(sobimg < x)

 

img = skimage.img_as_float(skid.astronaut())

 

# We take a portion of the image to show the details.

img = img[50:200, 150:300]

 

# We add Gaussian noise.

img_n = sku.random_noise(img)

show(img_n)

 


img_r = skimage.restoration.denoise_tv_bregman(

    img_n, 5.)

 

fig, (ax1, ax2, ax3) = plt.subplots(

    1, 3, figsize=(12, 8))

 

ax1.imshow(img_n)

ax1.set_title('With noise')

ax1.set_axis_off()

 

ax2.imshow(img_r)

ax2.set_title('Denoised')

ax2.set_axis_off()

 

ax3.imshow(img)

ax3.set_title('Original')

ax3.set_axis_off()

 



Share on :

0 Response to "Pengolahan Citra Biner"

Posting Komentar