Skip to content

PedroFellipeAntunes/halftone-java

Repository files navigation

Halftone

This project is a Java Maven application built 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/RGB colors.

Example 1 Example 2
Example 3 Example 4
Example Colored Dots


Table of Contents

  1. Features
  2. Usage
  3. How It Works
  4. Additional Examples

Features

  • Apply Halftone Effect
    • Patterns: Dots, Polygons, Triangles, Stippling, Lines, Sine Waves, Flow Lines.
  • Full CMYK/RGB Processing
    • Separates image into CMYK/RGB channels, applies halftone at predetermined angles, and merges using multiply/screen 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

  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: Choose between Default, CMYK or RGB for color 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

    To better understand the logic behind the kernels try out my kernel simulator!

  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/RGB Processing (Optional)

    • When CMYK/RGB mode is enabled, repeat steps 1–3 for each channel using fixed angles (e.g., CMYK(15°, 75°, 0°, 45°) or RGB(0º, 60º, 120º).
    • Finally, blend all channels using a multiply/screen operation to obtain the full-color halftone result.

Additional Examples

Angles:

Sphere 0 Sphere 1 Sphere 2 Sphere 3 Sphere 4

Wave crosshatching:

Example Lion Sine

Stippling:

Example Stippling

Flow Lines:

Flow Lines Full

Overlaying halftones at opposing angles to create a cross-hatching effect, by adding some rotation and spacing error we can mimic a hand made pattern. This effect can be further enhanced by generating an outline (e.g., with Extended Difference of Gaussians).

Example Original Example Manga like effect