Skip to main content

A library for learning and research purposes on image processing, performing piecewise linear transformations on grayscale and color images.

Project description

dttuong

The dttuong library is a Python library that helps process images with linear transformations, which can be applied to grayscale and color images.

Installation

To install this library, you can use pip:

pip install dttuong

Usage

import dttuong

Where:

input_path: input image path

output_path: output image path

auto_mode: is the linear transformation mode, with values ​​such as: auto_mode = "histogram" or auto_mode = "kmeans"
## How it works

- **`histogram` mode**: Segment the image based on the pixel distribution from the histogram.

- **`kmeans` mode**: Use the K-Means algorithm to cluster pixel values.

In addition, auto_mode = None, you can enter the value of breakpoints as you want

How to use dttuong library
Suppose you have an input.jpg image, you want to transform linearly each piece with automatic breakpoints using K-Means, you can run:

Here is a simple way to use

Gray image processing
import cv2
import matplotlib.pyplot as plt
from dttuong import process_gray_image

# Process gray image with automatic mode using K-Means
output_image = process_gray_image("input.jpg", auto_mode="kmeans")

# Display the result
plt.imshow(output_image, cmap="gray")
plt.title("Image After Transformation")
plt.show()

# Save the image
cv2.imwrite("output_gray.jpg", output_image)

Color Image Processing
import cv2
import matplotlib.pyplot as plt
from dttuong import process_color_image

# Color Image Processing with Auto Mode using Histogram
output_image = process_color_image("input.jpg", auto_mode="histogram")

# Display the result
plt.imshow(cv2.cvtColor(output_image, cv2.COLOR_BGR2RGB))
plt.title("Image After Transformation")
plt.show()

# Save the image
cv2.imwrite("output_color.jpg", output_image)

If you want to enter transformation points manually
from dttuong import process_gray_image

# Define the linear transformation points piecewise
breakpoints = [(0, 0), (100, 50), (150, 200), (255, 255)]

# Process grayscale image with custom transform points

output_image = process_gray_image("input.jpg", breakpoints=breakpoints)

# Save image
cv2.imwrite("output_manual.jpg", output_image)

Run the program from Terminal
If you want to write a separate script (main.py) to run it quickly:
from dttuong import process_gray_image

input_path = "input.jpg"
output_path = "output_gray.jpg"
auto_mode = "histogram" # Or "kmeans"

output_image = process_gray_image(input_path, auto_mode=auto_mode)
cv2.imwrite(output_path, output_image)

print(f"Image processed! The result is saved at: {output_path}")

Then run:
python main.py

Summary:
You just need to import process_gray_image or process_color_image from dttuong and call them with the appropriate parameters. 🚀

HHow to manually enter breakpoints
You just need to pass a list of breakpoints to the process_gray_image or process_color_image function.

Example: Processing grayscale images with manually entered breakpoints
import cv2
import matplotlib.pyplot as plt
from dttuong import process_gray_image

# Define the points of the piecewise linear transformation (x, y)
breakpoints = [(0, 0), (50, 30), (100, 120), (200, 220), (255, 255)]

# Image processing
output_image = process_gray_image("input.jpg", breakpoints=breakpoints)

# Display the result
plt.imshow(output_image, cmap="gray")
plt.title("Image After Transformation")
plt.show()

# Save the image
cv2.imwrite("output_gray_manual.jpg", output_image)
print("✅ Image saved successfully!")

Example: Process color images with manually entered breakpoints
import cv2
import matplotlib.pyplot as plt
from dttuong import process_color_image

# Define breakpoints
breakpoints = [(0, 0), (50, 30), (100, 120), (200, 220), (255, 255)]

# Process color images
output_image = process_color_image("input.jpg", breakpoints=breakpoints)

# Display the result
plt.imshow(cv2.cvtColor(output_image, cv2.COLOR_BGR2RGB))
plt.title("Image After Transformation")
plt.show()

# Save the image
cv2.imwrite("output_color_manual.jpg", output_image)
print(" Color image saved successfully!")
Summary
Define the list of breakpoints in the format:
breakpoints = [(0, 0), (50, 30), (100, 120), (200, 220), (255, 255)]

Call the process_gray_image() or process_color_image() function and pass in the breakpoints.

Save the image using cv2.imwrite("output.jpg", output_image).

Now you can manually input breakpoints and process photos as you like!

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dttuong-0.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dttuong-0.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file dttuong-0.1.tar.gz.

File metadata

  • Download URL: dttuong-0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.2

File hashes

Hashes for dttuong-0.1.tar.gz
Algorithm Hash digest
SHA256 6069d9c4d2e5bc0a38582a08303df080448111ac7b19fc643a167f3c0cc9c7e2
MD5 5745bca894de57276a7219d971c41b9a
BLAKE2b-256 7f6cc31035dc87026df805a6dcd5a5e5a4b7e4905efb435ea41f5074b969d58a

See more details on using hashes here.

File details

Details for the file dttuong-0.1-py3-none-any.whl.

File metadata

  • Download URL: dttuong-0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.2

File hashes

Hashes for dttuong-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0c944113827248be2f55d30dfde3a4cdc494fc4680eae6530742bea620d57d87
MD5 0e21e42b8663499dd226c6adc7640bc5
BLAKE2b-256 6e1257ec95d169c64f838fcdff06414272db8294a8e3b5abae06b8d60ef79348

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page