Encoder-Decoder Model for Grayscale to RGB Conversion

This script demonstrates creating and training an encoder-decoder model using random overlapping image patches.
5 download
Aggiornato 29 mag 2024

Visualizza la licenza

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

Cita come

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

Compatibilità della release di MATLAB
Creato con R2020b
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Versione Pubblicato Note della release
1.0.0