Oyyi

Gamma Correction

Apply gamma correction to adjust the brightness and contrast of an image in a non-linear way.

POST /api/image/gamma-correct

Request Parameters

Parameter Type Required Description
file File Yes The image file to process. Supported formats: JPEG, PNG, WebP, BMP, TIFF.
gamma Float No The gamma value to apply. Range: 0.1-5.0. Default: 1.0 (no change).

Response

Returns the gamma-corrected image in the same format as the input file.

Example Request

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

Example with Python

    import requests

url = "https://oyyi.xyz/api/image/gamma-correct"

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

data = {
    'gamma': 1.8
}

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

# Save the gamma-corrected image
with open('gamma_corrected.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('gamma', '1.8');

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

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

Gamma Values and Effects

Gamma < 1.0

Brightens the image, especially in darker areas. Values like 0.5-0.8 can help recover details in underexposed images.

Gamma = 1.0

No change to the image. This is the default value.

Gamma > 1.0

Darkens the image, especially in brighter areas. Values like 1.5-2.2 can help recover details in overexposed images.

How It Works

Gamma correction applies a non-linear transformation to each pixel value using the following formula:

pixel_new = 255 * (pixel_original / 255) ^ (1 / gamma)

This transformation adjusts the brightness and contrast of an image in a way that better matches human perception of brightness.

Error Responses

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

Notes

  • Gamma correction is applied to all color channels (RGB) but does not affect the alpha channel (transparency) if present.
  • Gamma correction is particularly useful for correcting images that appear too dark or too bright.
  • The maximum file size allowed is 10MB.
  • Unlike linear brightness adjustments, gamma correction preserves details in both shadows and highlights.
  • Standard gamma values for display calibration are typically around 2.2 for PC monitors and 1.8 for Mac displays.

Use Cases

  • Correcting underexposed (too dark) or overexposed (too bright) images
  • Enhancing details in shadows or highlights
  • Preparing images for different display devices with different gamma characteristics
  • Creating artistic effects by intentionally altering the gamma
  • Correcting images captured under different lighting conditions
  • Preparing images for print, which often requires different gamma settings than digital display