Encoder-Decoder Model for Grayscale to RGB Conversion

This script demonstrates creating and training an encoder-decoder model using random overlapping image patches.
5 téléchargements
Mise à jour 29 mai 2024

Afficher la licence

This script demonstrates how to create random overlapping patches of an image to train an encoder-decoder model that converts grayscale images to RGB images.
Some steps:
  • reading an example image (`peppers.png`)
  • call the function `image2patch_randperm_overlap` wiht the parameter
clc
clear
close all force
X = imread('peppers.png') ;
figure, imagesc(X), title('Example')
imageOut = mat2gray( X ) ;
imageIn = rgb2gray( imageOut ) ;
deltaX = 32 ;
deltaY = 32 ;
overlap = 8 ;
per = .8 ; % percent to train
seed = 1 ; % to control the random numbers
make_plot = 1 ;
[patchs] = image2patch_randperm_overlap( ...
imageIn , imageOut , deltaX , deltaY , overlap , seed , per , make_plot) ;
  • to visualizate the Train and Test data:
  • Encoder-Decoder Model: created using the Deep Neural Network designer
net = trainNetwork(patchs.train.In,patchs.train.Out,lgraph,options);
  • Computing the SSIM value (in average for the patchs) to get an idea of how well is the adjusted the model:
% SSIM_Training_Data = 0.8577
% SSIM_Testing_Data = 0.7857
  • Testing on the whole image (including the training patches):
  • Testing on a different Image (`cameraman.tif`):
Key Functions and Parameters
- **image2patch_randperm_overlap**: Generates random overlapping patches from the input images.
- **layer_Encoder_Decoder**: Script that defines the encoder-decoder network architecture.
- **trainingOptions**: Configures the training options for the network.
- **trainNetwork**: Trains the neural network.
- **mean_ssim**: Calculates the mean SSIM between predicted and actual images (for 4D matrices).
- **image2patch_overlap**: Converts an image into overlapping patches.
- **patch_overlap2image**: Converts patches back into a full image.
Conclusion
This script effectively demonstrates the process of creating and training an encoder-decoder model using random image patches and testing the model on both the training image and a new test image. The use of overlapping patches helps in reconstructing the full image during the prediction stage. This approach exemplifies how a deep learning model can be trained for the challenging task of converting grayscale images to RGB using a single image without repeating patches.
Author: Michael Alvarez
Email: michael.alvarez2@upr.edu

Citation pour cette source

Michael Alvarez (2025). Encoder-Decoder Model for Grayscale to RGB Conversion (https://fr.mathworks.com/matlabcentral/fileexchange/167061-encoder-decoder-model-for-grayscale-to-rgb-conversion), MATLAB Central File Exchange. Extrait(e) le .

Compatibilité avec les versions de MATLAB
Créé avec R2020b
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Publié le Notes de version
1.0.0