Enhancing Grayscale Japanese Spitz Images with a Modified Retinex Net

8–12 minutes
Enhancing Grayscale Japanese Spitz Images with a Modified RetinexNet

Enhancing grayscale images is a major challenge in computer vision, especially with subjects like Japanese Spitz dogs. These dogs, with their white fur, create particularly difficult images to process. Their photos often lack contrast, lose detail in bright areas, and fail to show important features clearly. 

Under poor lighting or in grayscale format, the problem worsens – facial features, fur textures, and body details blend together and become hard to distinguish. This loss of visual information reduces both the image quality and usefulness for important applications such as veterinary care, breed identification systems, and professional photography. 

To solve this problem, we developed an enhanced version of RetinexNet that improves the lighting component while keeping the dog’s natural features intact.

Background and related work

Image enhancement methods have advanced from basic techniques to complex AI models over the years. We tested three different approaches before choosing RetinexNet for our work with Japanese Spitz dogs.

RetinexNet works best for our needs because it handles uneven lighting well. It splits images into two parts and lets us improve the lighting without changing the dog’s natural features.

We also tested Zero-DCE, which is faster and doesn’t need paired training examples. However, it performed poorly in extreme lighting situations – a big problem when working with white-furred dogs.

The third option, CLAHE, is a simple and fast method that adjusts contrast locally. But it doesn’t understand what’s in the picture and often created unnatural results that lost the distinctive look of Japanese Spitz dogs.

What made RetinexNet stand out was its ability to separately handle lighting information. It keeps track of the illumination component throughout processing, allowing precise lighting adjustments while preserving texture.

Zero-DCE doesn’t separate these components, and CLAHE can’t preserve lighting information at all. This separation is especially important for Japanese Spitz images, where the bright white fur and environmental lighting create particularly difficult enhancement challenges.

Theoretical foundation: Retinex theory and image decomposition

Our approach is built on Retinex theory, developed by Edwin Land, which provides a powerful way to understand and enhance images. This theory suggests that any image can be split into two parts: what things actually look like and how they’re lit. 

Reflectance (R) is what an object would look like under perfect lighting. For Japanese Spitz dogs, their white fur has high reflectance values, while shadows have lower values. Think of reflectance as showing the “true appearance” of the dog, regardless of lighting conditions. During our training process, we make sure this component stays consistent even when lighting changes.

Illumination (I) represents how light falls on the scene. It changes smoothly across surfaces and shows which areas are bright or dark due to lighting. We train our system to keep this component smooth using special techniques. Simply put, illumination tells us how well-lit each part of the image is – low values mean shadows or underexposure, while high values indicate well-lit areas.

When these two components are multiplied together, they create the image we see:

Formally, for each pixel x in the grayscale image S, we assume S̃(x) = R(x) · Ĩ(x) where R(x) is the reflectance and Ĩ(x) is the illumination at x.

In logarithmic terms, this becomes an additive model log S = log R + log I, but we implement it multiplicatively in our network architecture.

What makes this approach powerful is how these components work together:

  • We can brighten an image by adjusting only the illumination while keeping the dog’s texture intact.
  • We can enhance details by adjusting reflectance without changing the lighting.
  • We can restore the original image by recombining reflectance with the original illumination.

This separation allows us to target specific improvements. For example, we can fix poor lighting without losing the natural look of the dog’s fur. This is especially valuable for Japanese Spitz images, where the white fur creates unique challenges under different lighting conditions.

input image

Input image

output retinex

Output

Our approach: RetinexNet architecture

Our approach follows the RetinexNet pipeline​, which consists of three main stages:

1. Decomposition

A convolutional subnetwork Decom-Net takes the input image S and predicts two outputs: a reflectance map R and an illumination map I. The network is trained so that R contains stable textures (independent of lighting) and I is smooth.

Since we don’t have “ground truth” examples of perfect decomposition, we train the network using constraints. For example, when training on paired low-light/normal-light images, the Decom-Net enforces that the two images share the same reflectance and that each illumination map is spatially smooth​. 

In our modified implementation, the Decom-Net is structured as a series of convolution-ReLU layers that split features into two channels (one for R, one for I), with sigmoid activations to keep values in [0,1][0,1].

2. Illumination adjustment

Next, a second subnetwork, Enhance-Net or Relight-Net, improves the lighting component. It takes the estimated I (and possibly R) and predicts an adjusted illumination Ĩ that brightens dark regions while maintaining plausible lighting.

This is typically implemented as an encoder-decoder CNN with skip connections and multiscale fusion​. The network can “see” both small details and the big picture by processing the image at different scales. It captures overall lighting patterns and then rebuilds a full-resolution improved lighting map. This step may also clean up noise in the reflectance component, especially in dark areas where camera noise is more visible.

3. Reconstruction

Finally, we recombine reflectance and illumination to form the enhanced image. The adjusted image is obtained by pixel-wise multiplication S̃(x) = R(x) · Ĩ(x). 

If we want to get back the original image, we can multiply the reflectance with the original illumination instead: R(x) · I(x) = S

In practice, after Enhance-Net produces Ĩ we multiply it by R (and optionally apply any final convolution) to produce the output. 

Thus, the overall RetinexNet pipeline is:

Decom-Net → (Enhance-Net adjusts I) → multiply to reconstruct image​.

original retinex scheme

This decomposition/relighting structure is illustrated in the ar5iv.org original scheme

Loss functions and training constraints

As mentioned earlier, training RetinexNet requires special losses, since we do not have ground-truth R or I. So, we designed a multi-term loss to guide learning​:

Reconstruction loss (LrecLrec​): Ensures the product of R and I matches the input. Formally, for each training image S, Lrec = ||R ⊙ I – S||²₂  where ⊙ denotes element-wise multiplication. This term penalizes any discrepancy between the decomposed components and the original image​.

Reflectance consistency loss (LirLir​): Enforces that the reflectance estimates for two images of the same scene (e.g. a low-light/normal-light pair) should be similar. If Rlow and Rnormal are the reflectance maps from a low-light image and its enhanced counterpart, we use Lir = ||Rlow – Rnormal||²₂. This “invariant reflectance” loss pushes the network to encode lighting changes solely in I and keep R invariant​.

Illumination smoothness loss (Lis): Encourages I to be spatially smooth while respecting edges. A basic total-variation (TV) loss ∑∣∇I∣ would oversmooth corners. Instead, a weighted TV is used: the gradient magnitude ∣∇I∣ is weighted by a function of ∣∇R∣ to avoid penalizing illumination changes at strong reflectance edges​. For example, Lis = ∑ₓ |∇I(x)| · exp(-α |∇R(x)|), where ∇ denotes spatial gradient and α is a weighting factor. 

The illumination smoothness term is weighted by the reflectance gradient, using a factor like exp(−λg∇Ri). This relaxes the constraint in regions with strong reflectance edges, allowing illumination to vary where image structures are present and discontinuities are expected.

Combining these, the overall Decom-Net loss is Ldecom = Lrec + λir Lir + λis Lis with coefficients λir, λis balancing the terms​. 

After decomposition, the Enhance-Net has a simpler loss: it typically uses LrecLrec​ on the final output (ensuring the brightened image matches the desired normal-light appearance) plus the same smoothness term for I. All networks are then fine-tuned end-to-end for consistency.

Implementation and modifications

We rebuilt the original RetinexNet code to make it more modern and easier to use. While we kept the core design, we made several improvements:

  • Updated the code to use current programming frameworks instead of the older TensorFlow 1.
  • Organized the code more clearly with better comments and structure via PyTorch or TensorFlow2.
  • Kept the same basic network design (3×3 filters, ReLU/sigmoid activations, and skip connections), but have optimized layer widths.
  • Ensured batch normalization and training stability
  • Modified the system to work specifically with grayscale images.

Since we’re working with grayscale Japanese Spitz images, we simplified parts of the original RetinexNet that dealt with color. This let us focus entirely on improving brightness and contrast rather than color accuracy. 

We also made the code modular, which means we can easily test different ways of adjusting the lighting without changing the entire system.

Experiments: illumination adjustment and reversibility

We tested our model on dark photos of Japanese Spitz dogs and found it worked well. The system brightened dark images while keeping important details in the fur clear and sharp.

One of the most important findings was that our enhancements are completely reversible. After splitting an image into reflectance and illumination, brightening it, and creating the improved version, we could also go backwards. 

By recombining the reflectance with the original lighting, we got back exactly the same image we started with. This proves our system truly separated the dog’s appearance from the lighting conditions.

We also ran tests to see what happens when we remove different parts of our training process (ablation):

  • Without the reflectance consistency rule, the model sometimes changed the brightness of objects incorrectly.
  • Without the smoothness rule, the lighting maps became noisy and unnatural.

These confirm the importance of each loss term as described in the original research.

Finally, we tested adjusting illumination by nonlinear operators (gamma correction on I within the network), which further improved dark region visibility while still allowing full revertibility to the original lighting.

Applications

Our method for improving image lighting has many practical uses in everyday technology:

  • Photography and video: This technique can fix dark photos or enhance security camera footage. Smartphones could use it to automatically improve photos taken in poor lighting.
  • Medical imaging: Doctors often work with low-contrast grayscale images. Our approach can separate the actual tissue structures from lighting problems, potentially helping with diagnoses.
  • Computer vision: Using the reflectance component instead of the raw image can help computers recognize objects more reliably under different lighting conditions.
  • Image editing: Photographers and designers could change the lighting in a scene without affecting the objects themselves – like making a daytime scene look like sunset or removing unwanted shadows.
  • Future uses: The technology could support other tasks like removing shadows completely, adding color to black-and-white images, or creating consistent lighting across multiple images.

The key advantage is that by separating what things look like from how they’re lit, we create new possibilities for improving and working with images in many fields.

Conclusion

We’ve shown how our modified RetinexNet system improves grayscale photos of Japanese Spitz dogs. The core idea is to decompose an image S into reflectance R and illumination I, adjust I through a dedicated network, and recombine to obtain the enhanced output.

The main advantages of our method are:

  • It’s easy to understand: the two components match what happens in real-world lighting.
  • It’s flexible: we can brighten images or change lighting while always being able to revert to the original.
  • It preserves details: the dog’s fur textures and features remain clear even after enhancement.

This approach works better than basic image enhancement for Japanese Spitz photos, creating naturally lit results that keep all the important details. The same principles could be used for many other applications where lighting is a problem. Future improvements might include making the system work in real-time, handling color photos better, or giving users more control over the lighting adjustments.

Most importantly, we’ve proven that separating what things look like from how they’re lit is a powerful approach to image enhancement – not just in theory, but in real-world results.

Leave a Reply

Discover more from Furnets

Subscribe now to keep reading and get access to the full archive.

Continue reading