Generate Overlapping Patches and Reconstruct the Image

버전 1.0.0 (4 KB) 작성자: Michael Alvarez
Generate overlapping patches from an input image, and then recover the image by smoothly fusing the overlap regions.
다운로드 수: 8
업데이트 날짜: 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