https://github.com/pedrofellipeantunes/halftone-java
Java program to apply a halftone filter to an image.
https://github.com/pedrofellipeantunes/halftone-java
graphics halftone hatching image-processing java manga swing
Last synced: 12 months ago
JSON representation
Java program to apply a halftone filter to an image.
- Host: GitHub
- URL: https://github.com/pedrofellipeantunes/halftone-java
- Owner: PedroFellipeAntunes
- Created: 2024-12-13T04:23:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-03T06:27:37.000Z (about 1 year ago)
- Last Synced: 2025-06-03T12:16:02.144Z (about 1 year ago)
- Topics: graphics, halftone, hatching, image-processing, java, manga, swing
- Language: Java
- Homepage:
- Size: 11.8 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Halftone
This project is a Java Maven application built using NetBeans IDE and Swing that applies the effect of **halftone** to an image, with dots, lines or sine waves as the pattern. This code uses a codebase from my other project to [separate the CMYK colors](https://github.com/PedroFellipeAntunes/color-separator-java).
---
## Table of Contents
1. [Features](#features)
2. [Usage](#usage)
3. [How It Works](#how-it-works)
4. [Additional Examples](#additional-examples)
---
## Features
- **Apply Halftone Effect**
- Patterns: `Dots`, `Squares`, `Triangles`, `Lines`, `Sine Waves`.
- **Full CMYK Processing**
- Separates image into CMYK channels, applies halftone at predetermined angles, and merges using multiply blend.
- **Drag & Drop Support**
- Simply drag images into the interface to process them.
- **Interactive Controls**
- Adjust halftone scale (0–100) and angle (0°–360°) via sliders for live preview.
- **Batch Processing**
- Drop multiple images at once; each will be processed and automatically saved.
---
## Usage
1. **Open the Application**
- Double-click `Halftone.jar`, or run:
```
java -jar Halftone.jar
```
2. **Configure Settings**
- **Pattern:** Choose between Dots, Squares, Triangles, Lines or Sine Waves.
- **Scale Slider:** Adjust the size of the halftone elements (0 = minimum, 100 = maximum).
- **Angle Slider:** Define the angle of the halftone pattern (0°–360°).
- **Color Mode:** Toggle “CMYK” to enable or disable per-channel processing.
3. **Drag & Drop**
- Drag one or more images (JPEG, PNG, JPG) directly into the window.
4. **Preview and Save**
- A live preview will display the result.
- To save, click **Save** or close the window. Processed images are saved in the same folder as the originals with this pattern:
```
originalname_Halftone[type,scale,angle].png
```
- Example: `cameraman_Halftone[Lines,50,45.0].png`
---
## How It Works
Below is a high-level overview of the halftone algorithm (example based on line/sine patterns):
1. **Kernel Generation**
- Divide the image into square blocks (“kernels”), each rotated by the chosen angle.
- For each kernel, sum up the RGB values and compute the average.
2. **Luminance Calculation**
- Within each kernel, convert the average color to luminance.
- Determine a center point and compute two offset points based on luminance, constrained to half the kernel size.
3. **Polygon Filling**
- Negative offsets define the top of a polygon, positive offsets define the bottom.
- Connect these points along each row to create a complex shape that follows the image’s contours at the given angle.
4. **CMYK Processing (Optional)**
- When CMYK mode is enabled, repeat steps 1–3 for each channel (Cyan, Magenta, Yellow, Key/Black) using fixed angles (e.g., 15°, 75°, 0°, 45°).
- Finally, blend all channels using a multiply operation to obtain the full-color halftone result.
---
## Additional Examples
Overlaying halftones at opposing angles with the dark layer at 50% opacity to create a cross-hatching effect.
This effect can be further enhanced by generating an outline (e.g., with Extended Difference of Gaussians).
---