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
引用格式
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. 检索时间: .
MATLAB 版本兼容性
创建方式
R2020b
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.0.0 |