|
Python yordamida mashina o‘rganishda tasvirni qayta ishlashni qo‘llash
|
bet | 89/182 | Sana | 19.05.2024 | Hajmi | 5,69 Mb. | | #244351 |
Bog'liq Python sun\'iy intellekt texnologiyasi Dasrlik 2024Python yordamida mashina o‘rganishda tasvirni qayta ishlashni qo‘llash
Sayohatning ushbu qismida biz tasvirimizdan xususiyatlarni qanday olishimiz va bu xususiyatlardan Machine Learning modelimiz xususiyatlari sifatida foydalanishimiz mumkinligini muhokama qilamiz. Bizning holatimiz uchun biz tasniflash qilamiz.
Muhokama davomida biz quyidagi kutubxonalardan foydalanamiz.
# Basic imports
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Image Processing
from skimage.io import imread, imshow
from skimage.color import rgb2gray
from skimage.morphology import opening
from skimage.measure import label, regionprops
from skimage.filters import threshold_otsu
Xususiyatlarni chiqarish
Ushbu xususiyatlarni namunali rasmda olish uchun quvur liniyasini yaratish orqali ushbu usulni qo‘llaymiz. Bizning misolimiz uchun biz quyidagi rasmdan foydalanamiz.
# Load the image
img = imread('TS_midnights.jpg’)[:, :, :3]
# Plot the image
fig, ax = plt.subplots(1, 1, figsize=(5, 5))
ax.imshow(img)
ax.set_title("Midnights Album Cover")
ax.set_axis_off()
plt.show()
7.1.3-rasm. Xususiyatlarni chiqarish
Ushbu rasmning xususiyatlarini matn sarlavhasida aniqlaymiz.
# Preprocess image by grayscaling and binarizing
image_gs = rgb2gray(img[100:180, 120:400, :3])
thresh = threshold_otsu(image_gs)
image_bw = image_gs < thresh
image_clean = image_bw.copy()
# Image cleanining through morphological operation
image_clean = image_bw.copy()
image_clean = opening(image_clean)
# Get the properties of objects
image_labels = label(image_clean)
image_props = regionprops(image_labels)
# Plot the image
fig, ax = plt.subplots(2, 1, figsize=(5, 5))
ax[0].imshow(image_bw, cmap='gray')
ax[0].set_title("Cut-out text in Midnights Album")
ax[0].set_axis_off()
ax[1].imshow(leaf_props[0].image, cmap='gray')
ax[1].set_title("Text M in the Title")
ax[1].set_xticks([])
ax[1].set_yticks([])
ax[1].set_xticklabels([])
ax[1].set_yticklabels([])
plt.show()
# Print out the properties of this letter
print(f'Area: {image_props[0].area:.2f}')
print(f'Perimeter: {image_props[0].perimeter:.2f}')
print(f'Bounding Box Area: {image_props[0].bbox_area:.2f}')
print(f'Convex Area: {image_props[0].convex_area:.2f}')
print(f'Eccentricity: {image_props[0].eccentricity:.2f}')
print(f'Major Axis Length : {image_props[0].major_axis_length:.2f}')
print(f'Minor Axis Length: {image_props[0].minor_axis_length:.2f}')
print(f'Solidity: {image_props[0].solidity:.2f}')
7.1.4-rasm.Midnights oynasi
Area: 934.00
Perimeter: 268.57
Bounding Box Area: 1332.00
Convex Area: 1328.00
Eccentricity: 0.48
Major Axis Length : 46.44
Minor Axis Length: 40.79
Solidity: 0.70
Ushbu xususiyatlardan mashinali o‘qitish modelining xususiyatlari sifatida foydalanib, biz tasniflashimiz mumkin. Hozircha bu ahamiyatsiz, chunki biz ushbu rasmda hech narsani tasniflamaymiz.
|
| |