Showing posts with label Image Enhancement. Show all posts
Showing posts with label Image Enhancement. Show all posts

Monday, January 15, 2024

Why Scikit-Learn For Machine Learning and Image Processing !


The Python computer language library for machine learning known as scikit-learn, which is also often referred to as scikit, is openly accessible and may be updated by anybody. For the purpose of data analysis and modeling, the program provides capabilities that are both user-friendly and effective. A wide variety of machine learning techniques and utilities are included in these tools. These tools can be used for a variety of tasks, including classification, regression, clustering, dimensionality reduction, and model selection.

Among the most important characteristics of scikit-learn are:

Consistent API

Scikit-learn is able to retain a consistent and user-friendly application programming interface (API) across all of its numerous algorithms. Because of this uniformity, the process of testing with different algorithms and models is made much easier.

Supervised and Unsupervised Learning

Scikit-learn is capable of supporting both supervised and unsupervised learning strategies inside its framework. Classification, regression, clustering, dimensionality reduction, and other functions are among the methods that are included in this package.

User-Friendliness

The library was developed with ease of use in mind, making it accessible to users of all experience levels, from novices to seasoned professionals. The documentation and examples are presented in a comprehensible manner.

Integration with NumPy and SciPy

Scikit-learn is able to integrate without any problems with other well-known scientific computing libraries written in Python, such as NumPy and SciPy. This makes it possible to manipulate and analyze data in an effective manner.

Model Evaluation and Selection

Scikit-learn offers a set of tools that may be used to evaluate the performance of machine learning models. These tools include metrics for classification, regression, and clustering. In addition to that, it provides functionality for adjusting hyperparameters and selecting models accordingly.

Data Preprocessing

The library contains tools for preprocessing data, including as scaling, encoding categorical variables, addressing missing values, and producing train-test splits. These tools are included in the library.

Wide Range of Algorithms

Scikit-learn encompasses a wide variety of machine learning techniques, such as linear models, support vector machines, decision trees, ensemble methods (random forests, gradient boosting), k-nearest neighbors, clustering algorithms, and many more. It is a comprehensive tool for learning machine learning.

Community and Support

Because it is open-source, scikit-learn has a large and lively community of software users. Support is available to users via several channels, including manuals, forums, and community-driven development.

Example Usage:

from sklearn import datasets

from sklearn.model_selection import train_test_split

from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import accuracy_score

# Load a dataset (e.g., Iris dataset)

iris = datasets.load_iris()

X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=42)

# Create and train a Random Forest classifier

clf = RandomForestClassifier(n_estimators=100, random_state=42)

clf.fit(X_train, y_train)

# Make predictions on the test set

y_pred = clf.predict(X_test)

# Evaluate the accuracy

accuracy = accuracy_score(y_test, y_pred)

print(f"Accuracy: {accuracy}")

For the purpose of this illustration, scikit-learn is used to load the Iris dataset, divide it into training and testing sets, develop a Random Forest classifier, train the model, generate predictions, and assess the correctness of the model. This is an example of the normal process that scikit-learn makes possible for machine learning tasks.


This is the introduction of Scikit-Learn library so far. We will learn more about the usage of Scikit-Learn for Image Processing and Machine Learning in the upcoming context. Keep in touch and Good Luck!


Sunday, January 14, 2024

Python Imaging Library (PIL): Image Processing and Image Enhancement

 PIL, also referred to as the Python Imaging Library, is an open-source library specifically created for editing pictures in the Python programming language. The program provides a wide range of image processing capabilities and is compatible with several image file formats. Since 2011, the original PIL project has stopped being actively maintained, and Pillow, a derivative of PIL, has replaced it as the updated version. Pillow is now undergoing vigorous development and is the favored choice for doing image processing tasks in the Python computer language.

ImageEnhance Module

The Python Imaging Library (PIL), also known as the Pillow library, offers the ImageEnhance module which consists of a collection of classes designed to enhance various aspects of images such as contrast, brightness, sharpness, and color. This module is beneficial for making basic modifications to the visual aesthetics of images. The ImageEnhance module works in conjunction with Pillow's Image objects.

Color

class PIL.ImageEnhance.Color(image)
Adjust the color balance of the image. This class is used for the purpose of adjusting the color balance of an image. Resembling the controls seen on a color television set. A zero enhancement factor results in a grayscale image. A factor of 1.0 results in the exact replication of the original image.

Code Example:
from PIL import Image
from PIL import ImageEnhance
# open image for color enhancement
image = Image.open("drd.jpg") # original image
color_enhance = ImageEnhance.Color(image)
images = []
for i in range(8):
    factor = i / 4.0
    im = color_enchance.enhance(factor)
    images.append(im)
import matplotlib.pyplot as plt     # display images in 2x4 grid
fig, axes = plt.subplots(2, 4, figsize = (12, 6))
for i, ax in enumerate(axes.flat):
    if i < len(images):
        ax.imshow(images[i])
        ax.axis('off')
plt.show()
Original Image

Image Color Enhancement

Contrast

class PIL.ImageEnhance.Contrast(image)
Modify the contrast of the picture. The purpose of this class is to manage the contrast of an image, similarly much to the contrast adjustment seen on a television screen. A factor of 0.0 produces a completely gray image, whereas a factor of 1.0 preserves the original image. Higher values amplify the contrast of the image.
Code Example:
from PIL import Image
from PIL import ImageEnhance
# open image for contrast enhancement
image = Image.open("drd.jpg") # original image
contrast_enhance = ImageEnhance.Contrast(image)
images = []
for i in range(8):
    factor = i / 4.0
    im = contrast_enchance.enhance(factor)
    images.append(im)
import matplotlib.pyplot as plt     # display images in 2x4 grid
fig, axes = plt.subplots(2, 4, figsize = (12, 6))
for i, ax in enumerate(axes.flat):
    if i < len(images):
        ax.imshow(images[i])
        ax.axis('off')
plt.show()
Original Image

Image Contrast Enhancement

Brightness

class PIL.ImageEnhance.Brightness(image)
Adjust the brightness of the image. The purpose of this class is to regulate the brightness of an image. A factor of 0.0 results in a completely dark picture, whereas a factor of 1.0 maintains the original image. Higher values of the factor increase the brightness of the image.
Code Example:
from PIL import Image
from PIL import ImageEnhance
# open image for brightness enhancement
image = Image.open("drd.jpg") # original image
brightness_enhance = ImageEnhance.Brightness(image)
images = []
for i in range(8):
    factor = i / 4.0
    im = brightness_enchance.enhance(factor)
    images.append(im)
import matplotlib.pyplot as plt     # display images in 2x4 grid
fig, axes = plt.subplots(2, 4, figsize = (12, 6))
for i, ax in enumerate(axes.flat):
    if i < len(images):
        ax.imshow(images[i])
        ax.axis('off')
plt.show()
Original Image

Image Brightness Enhancement

Sharpness

class PIL.ImageEnhance.Sharpness(image)
Adjust image sharpness. This class can be used to adjust the sharpness of an image. An enhancement factor of 0.0 gives a blurred image, a factor of 1.0 gives the original image, and a factor of 2.0 gives a sharpened image.
Code Example:
from PIL import Image
from PIL import ImageEnhance
# open image for sharpness enhancement
image = Image.open("drd.jpg") # original image
sharpness_enhance = ImageEnhance.Sharpness(image)
images = []
for i in range(8):
    factor = i / 4.0
    im = sharpness_enchance.enhance(factor)
    images.append(im)
import matplotlib.pyplot as plt     # display images in 2x4 grid
fig, axes = plt.subplots(2, 4, figsize = (12, 6))
for i, ax in enumerate(axes.flat):
    if i < len(images):
        ax.imshow(images[i])
        ax.axis('off')
plt.show()
Original Image

Image Sharpness Enhancement