Generate Overlapping Patches and Reconstruct the Image

版本 1.0.0 (4.0 KB) 作者: Michael Alvarez
Generate overlapping patches from an input image, and then recover the image by smoothly fusing the overlap regions.
15.0 次下载
更新时间 2024/5/23

查看许可证

This script demonstrates how to create overlapping patches from an image and subsequently combine them back into a single image. The process involves two main functions:
1. image2patch_overlap: This function takes an input image and divides it into overlapping patches. It requires the following parameters:
- `imageIn`: The input image to be divided.
- `deltaX`, `deltaY`: The step sizes in the x and y directions, respectively.
- `overlap`: The amount of overlap between adjacent patches.
The function outputs the generated patches, updated dimensions, and the indices `iX` and `iY` that mark the positions of the patches.
2. patch_overlap2image: This function takes the overlapping patches and combines them back into a single image. It requires the following parameters:
- `patchs`: The input patches to be combined.
- `iX`, `iY`: The indices marking the positions of the patches.
- `overlap`: The amount of overlap between adjacent patches.
- `show_masks`: A flag to indicate whether to display the masks used for combining the patches.
The function outputs the reconstructed image and the updated dimensions.
Additionally, the script includes a helper function `my_sigmoid`, which defines the sigmoid operation commonly used in various computations. The sigmoid function provides the weighted values for the overlap regions, ensuring a perfect match between the patches.
% This script is an example of create patches of an image that are overlaped and after combined
%
%
% Michael Alvarez
% michael.alvarez2@upr.edu
% -------------------------------------------------------------------------
close all
close all
clear
% Example of path images with overlap
X = imread('cameraman.tif');
figure, imagesc(X), title('Original'), axis square,
deltaX = 70 ;
deltaY = 70;
overlap = 10 ;
[ patchs , mn_new1 , iX , iY ] = image2patch_overlap( X , deltaX , deltaY , overlap) ;
% show the patches
figure,
cont_subplot = 0 ;
for row = 1 : size( iX , 1 )
for col = 1 : size( iY , 1 )
cont_subplot = cont_subplot + 1 ;
subplot( size( iX , 1 ) , size( iY , 1 ) , cont_subplot ),
imagesc( patchs(:,:,:,cont_subplot) ), axis off, axis square,
end
end
% the last input in patch_overlap2image function is to show the masks that
% I use to combine the patchs making an smoth transition between the patchs
[ imageOut , mn_new2 ] = patch_overlap2image( patchs , iX , iY , overlap , 1 ) ;
figure, imagesc( imageOut ), title('Recover'), axis square,
Note: The final size of the recovered image can be smaller than the original image because the last pixels in columns and rows are intentionally removed to avoid creating patches with more overlap than defined by the variable 'overlap'.
Author: Michael Alvarez
Email: michael.alvarez2@upr.edu

引用格式

Michael Alvarez (2024). Generate Overlapping Patches and Reconstruct the Image (https://www.mathworks.com/matlabcentral/fileexchange/166391-generate-overlapping-patches-and-reconstruct-the-image), 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