Oyyi

Adaptive Contrast Enhancement

Apply adaptive contrast enhancement using CLAHE (Contrast Limited Adaptive Histogram Equalization) for superior local contrast improvement.

POST /api/image/adaptive-contrast

Request Parameters

ParameterTypeRequiredDescription
fileFileYesThe image file to process. Supported formats: JPEG, PNG, WebP, BMP, TIFF.
clip_limitFloatNoContrast limit for localized changes. Higher values result in more contrast. Range: 0.5-10.0. Default: 2.0.
tile_grid_sizeIntegerNoSize of grid for histogram equalization. Smaller values enhance local details. Range: 2-16. Default: 8.

Response

Returns the contrast-enhanced image in the same format as the input file.

Example Request

    curl -X POST "https://oyyi.xyz/api/image/adaptive-contrast" \
  -H "accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@image.jpg" \
  -F "clip_limit=2.0" \
  -F "tile_grid_size=8" \
  --output enhanced.jpg
  

Example with Python

    import requests

url = "https://oyyi.xyz/api/image/adaptive-contrast"

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

data = {
    'clip_limit': 2.0,
    'tile_grid_size': 8
}

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

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

Example with JavaScript

    // Using fetch API
const formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('clip_limit', '2.0');
formData.append('tile_grid_size', '8');

fetch('https://oyyi.xyz/api/image/adaptive-contrast', {
  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 = 'enhanced.jpg';
  a.click();

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

How It Works

CLAHE (Contrast Limited Adaptive Histogram Equalization) is an advanced contrast enhancement technique that improves upon standard histogram equalization:

  • The image is divided into small tiles (grid cells) based on the tile_grid_size parameter.
  • Histogram equalization is applied to each tile independently, enhancing local contrast.
  • The clip_limit parameter prevents over-amplification of noise by limiting the contrast enhancement.
  • Bilinear interpolation is used to eliminate artificial boundaries between tiles.
  • This approach enhances local details while maintaining the overall appearance of the image.

Parameter Effects

Clip Limit

  • Lower values (0.5-1.5): Subtle enhancement, less noise amplification
  • Medium values (2.0-4.0): Balanced enhancement for most images
  • Higher values (4.0-10.0): Strong enhancement, may amplify noise

Tile Grid Size

  • Smaller values (2-4): Enhances very local details, may look unnatural
  • Medium values (8): Good balance for most images
  • Larger values (12-16): More global enhancement, similar to regular histogram equalization

Error Responses

Status CodeDescription
400Bad request. Missing required parameters, invalid parameter values, 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

  • CLAHE is particularly effective for enhancing details in medical images, foggy scenes, and underwater photography.
  • For color images, the enhancement is applied to the luminance/value channel only, preserving the hue and saturation.
  • Higher clip limits can amplify noise in smooth areas of the image.
  • Smaller tile sizes enhance local details but may create an unnatural appearance.
  • The maximum file size allowed is 10MB.
  • This operation preserves the alpha channel (transparency) if present in the original image.

Use Cases

  • Enhancing medical imaging data like X-rays, CT scans, or ultrasound images
  • Improving visibility in foggy, hazy, or underwater images
  • Enhancing details in satellite or aerial imagery
  • Preprocessing images for computer vision and object detection
  • Improving the readability of scanned documents with uneven lighting
  • Enhancing details in photographs with challenging lighting conditions

Comparison with Regular Contrast Enhancement

Unlike regular contrast enhancement or histogram equalization, CLAHE:

  • Enhances local contrast rather than global contrast
  • Preserves details in both dark and bright regions simultaneously
  • Prevents over-amplification of noise through contrast limiting
  • Adapts to different regions of the image based on local content
  • Produces more natural-looking results for many types of images