An open API service indexing awesome lists of open source software.

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.

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).








Example 1


Example 2




Example 3


Example 4





Example Colored Dots


---

## 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.


Interface

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.


Step 1: Kernel Generation

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.


Step 2: Luminance and Offsets

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.


Step 3: Polygon Filling

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


Sphere 0
Sphere 1
Sphere 2
Sphere 3
Sphere 4


Example Lion Sine


Example 5
Example 6

Overlaying halftones at opposing angles with the dark layer at 50% opacity to create a cross-hatching effect.


Example 7

This effect can be further enhanced by generating an outline (e.g., with Extended Difference of Gaussians).


Example 8

---