Oyyi

Histogram Equalization

Apply histogram equalization to enhance image contrast by redistributing pixel intensities.

POST /api/image/histogram-equalization

Request Parameters

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

Response

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

Example Request

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

Example with Python

    import requests

url = "https://oyyi.xyz/api/image/histogram-equalization"

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

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

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

Example with JavaScript

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

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

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

How It Works

Histogram equalization is a technique used to enhance the contrast of an image by redistributing pixel intensity values:

  • The algorithm calculates the histogram of the image, which shows the distribution of pixel intensities.
  • It then computes a cumulative distribution function (CDF) from the histogram.
  • The CDF is normalized and used as a mapping function to transform the original pixel values.
  • This process spreads out the most frequent intensity values, effectively increasing the global contrast of the image.

Error Responses

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

  • Histogram equalization works best on images with poor contrast due to lighting conditions or sensor limitations.
  • The technique is particularly effective for scientific images like X-rays, thermal images, or microscopy images.
  • For color images, the equalization is applied to the luminance/value channel only, preserving the hue and saturation.
  • While histogram equalization enhances global contrast, it may sometimes lead to over-enhancement or unnatural-looking results.
  • The maximum file size allowed is 10MB.
  • This operation preserves the alpha channel (transparency) if present in the original image.

Use Cases

  • Enhancing low-contrast images due to poor lighting conditions
  • Improving visibility in foggy or hazy images
  • Enhancing medical imaging data like X-rays or MRIs
  • Preprocessing images for computer vision applications
  • Improving the readability of scanned documents
  • Enhancing details in underexposed or overexposed photographs