TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Adarsh275/Image-Transformation/llms.txt
Use this file to discover all available pages before exploring further.
imageEdit class exposes ten transformation methods, each of which reads from self.inp (populated by loadImg()) and writes its result into self.outp. Some methods return self.outp explicitly; others set it in place and return None. Several methods are interactive — they call Python’s built-in input() to collect parameters at runtime, which means they will block and wait for keyboard input when invoked. All methods require loadImg() to have been called first.
grayscale()
R×0.299 + G×0.587 + B×0.114 is computed for every pixel, and the resulting scalar luminance value is written back into all three channels of a copy of self.inp, preserving the original three-channel shape. This means the output is still a 3-channel array — it simply appears grey because all channels carry the same value.
- Prompt: None
- Output dtype: same as
self.inp(typicallyfloat32for PNG,uint8for JPEG) - Output shape: same as
self.inp—(H, W, 3) - Returns:
self.outp
edgeDetection()
grayscale() is called first to produce a luminance array, and then the vertical and horizontal Sobel kernels are convolved with each 3×3 neighbourhood. The edge score at each pixel is computed as sqrt(vertical_score² + horizontal_score²), where each score is the element-wise product of the kernel and the local 3×3 patch, summed and divided by 4. The resulting edge-score map is normalised to [0, 1] by dividing by its own maximum value.
Because the convolution requires a full 3×3 neighbourhood, a 3-pixel border around the image is left as zero (black). This is an expected artefact of the sliding-window approach used.
- Prompt: None
- Output dtype:
float64 - Output shape: same as
self.inp—(H, W, 3) - Returns:
self.outp
invertColor()
self.inp. For an 8-bit unsigned integer array, ~pixel_value is equivalent to 255 - pixel_value, so bright pixels become dark and dark pixels become bright, with colours shifted to their complements.
- Prompt: None
- Input requirement:
self.inpmust be auint8array. Calling this on afloatarray (e.g., a PNG loaded by Matplotlib) will produce incorrect results because bitwise NOT on float bytes yields meaningless values. - Output dtype:
uint8(same as input) - Output shape: same as
self.inp - Returns:
None(setsself.outpin place)
contrast()
[0, percentage/100 × 255]. Percentile clipping removes extreme highlights and shadows before rescaling, which prevents a small number of very bright or very dark pixels from compressing the rest of the tonal range. The output is cast to uint8.
- Prompt:
Enter contrast percentage:— expects an integer (e.g.,80). A value of100rescales to the full[0, 255]range; lower values compress the output range, producing a darker result. - Output dtype:
uint8 - Output shape: same as
self.inp - Returns:
None(setsself.outpin place)
rgbchannel()
self.inp’s shape is created, and only the channels named in the user’s input are copied from self.inp. For example, entering rb keeps the red and blue channels and zeroes the green channel, producing a magenta-tinted image. The method loops indefinitely until valid input matching the pattern ^r?g?b?$ is received.
- Prompt:
Enter channel composition:— a string containing any combination of the charactersr,g, andbin that order (e.g.,r,g,b,rg,rb,gb,rgb). Input is lowercased automatically. - Validation: checked against the regular expression
^r?g?b?$; any string containing characters other thanr,g, orb(in that order) causes the prompt to repeat. Note that an empty string technically matches the pattern and is accepted, resulting in all channels being zeroed (a black image). - Output dtype:
uint8 - Output shape: same as
self.inp—(H, W, 3) - Returns:
None(setsself.outpin place)
transparency()
(H, W, 4) array of zeros is initialised, the RGB channels are copied from self.inp, and the alpha channel is filled uniformly with int((100 - percentage) / 100 × 255). A percentage of 0 yields an alpha of 255 (fully opaque); a percentage of 100 yields an alpha of 0 (fully transparent).
- Prompt:
Enter transparency percentage:— expects a float in the range[0, 100]. - Output dtype:
uint8 - Output shape:
(H, W, 4)— one extra channel compared to a standard RGB input - Returns:
None(setsself.outpin place)
flip()
numpy.fliplr. Every row of pixels is reversed in place, producing a mirror image around the vertical axis. This is a lossless operation — no interpolation is performed and no pixel values are altered.
- Prompt: None
- Output dtype: same as
self.inp - Output shape: same as
self.inp - Returns:
None(setsself.outpin place)
rotate()
uint8.
The entered angle is stored as self.ang (integer degrees). The CLI uses self.ang when building the output filename suffix, so this attribute must remain set after the method returns.
- Prompt:
Enter angle in degrees:— expects a positive or negative integer (e.g.,45,-90,180). - Output dtype:
uint8 - Output shape:
(new_H, new_W, C)wherenew_Handnew_Ware larger than the originals for most non-axis-aligned angles - Returns:
None(setsself.outpin place)
upscale()
f times along both axes via numpy.ndarray.repeat, which means a (H, W, C) input becomes (H×f, W×f, C). Because it repeats exact pixel values rather than interpolating, the result has a blocky, pixelated appearance at large factors — this is fast but lower quality than interpolation-based upscaling.
- Prompt:
Enter scaling factor:— expects a positive integer (e.g.,2,3). - Output dtype: same as
self.inp - Output shape:
(H×f, W×f, C) - Returns:
None(setsself.outpin place)
downscale()
f-th pixel is selected along both axes via array slicing (self.inp[::f, ::f]), so a (H, W, C) input produces approximately (H//f, W//f, C). No averaging or anti-aliasing is applied — pixels between the sampled positions are discarded entirely, which can introduce aliasing on fine detail at large factors.
- Prompt:
Enter downscale factor:— expects a positive integer (e.g.,2,4). - Output dtype: same as
self.inp - Output shape:
(H//f, W//f, C) - Returns:
None(setsself.outpin place)
resize()
| Width factor | Height factor | Strategy |
|---|---|---|
> 1 | > 1 | Both axes upscaled via repeat |
> 1 | <= 1 | Width upscaled, height downscaled — columns subsampled at stride int(w), rows repeated by factor h |
<= 1 | > 1 | Height upscaled, width downscaled — rows subsampled at stride int(h), columns repeated by factor w |
<= 1 | <= 1 | Both axes downscaled via stride slicing ([::int(1/h), ::int(1/w)]) |
- Prompts:
Enter scaling factor for width:— float (e.g.,1.5to widen by 50 %,0.5to halve width)Enter scaling factor for height:— float (e.g.,2.0to double height)
- Output dtype: same as
self.inp - Output shape: varies depending on factors
- Returns:
None(setsself.outpin place)
resize() is not exposed as a CLI command — it is only accessible through
the Python API. Use upscale() or downscale() if you are working via the
command line and need uniform scaling.Worked Example: Multiple Transforms on Different Images
The pattern below shows how to apply different transformations to separate images in the same script. Each transformation uses its ownimageEdit instance to avoid the self.dest mutation issue described in the imageEdit Class reference.