Oyyi

Sharpen Image

Enhance the details and edges in an image by applying a sharpening filter.

POST /api/image/sharpen

Request Parameters

ParameterTypeRequiredDescription
fileFileYesThe image file to sharpen. Supported formats: JPEG, PNG, WebP, BMP, TIFF.

Response

Returns the sharpened image in the same format as the input file.

Example Request

    // example.sh
curl -X POST "https://oyyi.xyz/api/image/sharpen"   -H "accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@image.jpg" \
  --output sharpened.jpg
  

Example with Python

    // sharpen.py
import requests

url = "https://oyyi.xyz/api/image/sharpen"

files = {
    'file': open('image.jpg', 'rb')
}

data = {}

response = requests.post(url, files=files, data=data)

# Save the sharpened image
with open('sharpened.jpg', 'wb') as f:
    f.write(response.content)
  

Example with JavaScript

    // sharpen.js
// Using fetch API
const formData = new FormData();
formData.append('file', fileInput.files[0]);

fetch('https://oyyi.xyz/api/image/sharpen', {
  method: 'POST',
  body: formData
})
.then(response => response.blob())
.then(blob => {
  // Create a URL for the blob
  const url = URL.createObjectURL(blob);

  // Create a link to download the image
  const a = document.createElement('a');
  a.href = url;
  a.download = 'sharpened.jpg';
  a.click();

  // Clean up by revoking the URL
  URL.revokeObjectURL(url);
})
.catch(error => console.error('Error:', error));
  

Sharpening Methods

Unsharp Mask

Creates a blurred version of the image and subtracts it from the original to enhance edges. Provides more control and typically better results.

Laplacian

Uses a Laplacian filter to detect edges and enhance them. More aggressive and can create stronger edge effects.

Sharpening Strength Examples

Low Strength (0.1-0.5)

Subtle sharpening, good for already sharp images

Medium Strength (0.5-1.5)

Moderate sharpening, good for most use cases

High Strength (1.5-5.0)

Strong sharpening, may introduce noise or artifacts

How It Works

Image sharpening works by increasing the contrast between adjacent pixels, particularly at edges:

  • Unsharp Mask: Despite its name, this technique actually sharpens the image. It works by:
    1. Creating a blurred (unsharp) version of the original image
    2. Subtracting this blurred version from the original to identify edges
    3. Adding a weighted version of these edges back to the original image
  • Laplacian: This method uses a Laplacian filter to detect areas of rapid intensity change (edges) and enhances them. It's more direct but can be more prone to enhancing noise.

Error Responses

Status CodeDescription
400Bad request. Missing required parameters, invalid strength value, invalid method, or invalid file format.
413Payload too large. The file size exceeds the maximum allowed limit.
500Internal server error. Something went wrong on the server.

Notes

  • The sharpening effect is implemented using an unsharp mask filter by default, which enhances edges while minimizing noise amplification.
  • Higher strength values will result in more pronounced sharpening but may introduce artifacts or noise.
  • Sharpening is most effective on slightly blurry or soft images.
  • Over-sharpening can create halos around edges and amplify noise, so use higher strength values with caution.
  • The radius parameter (for unsharp mask) controls how wide the edge enhancement effect extends. Larger values affect wider areas around edges.
  • The maximum file size allowed is 10MB.
  • This operation preserves the alpha channel (transparency) if present in the original image.

Use Cases

  • Enhancing details in slightly blurry photos
  • Improving text readability in scanned documents
  • Bringing out texture details in product photography
  • Correcting soft focus in portraits
  • Enhancing architectural or landscape photography
  • Improving the clarity of images that will be printed