How to create a crumpled (wrinkled) paper effect on an image?

10 visualizzazioni (ultimi 30 giorni)
Could you please help me to create a crumpled paper effect on an image in matlab?

Risposta accettata

DGM
DGM il 2 Giu 2022
The answer is fairly simple, but it depends what you expect. The basic concept isn't a MATLAB problem at all. Solving the problem starts with knowing how to do it in concept -- which is something for which there are plenty of photoshop tutorials.
That said, asking how to do it in MATLAB is a fair question. It can certainly be done with base MATLAB and IPT tools, but it won't be convenient or apparent. I'm going to use MIMT tools here, since MATLAB/IPT don't have any blending or composition tools. The displacement mapping can likely be done with imwarp(). The specific usage of imlnc() isn't directly replicable with other tools, but imadjust() is likely sufficient.
FG = imread('crumpledpaper.jpg');
BG = imread('peppers.png');
% prepare FG and match geometry
FG = rgb2gray(FG);
FG = imresize(FG,imsize(BG,2));
% shift the distribution of FG to be roughly centered about 50% gray
% here, imlnc() applies a nonlinear curve using gamma and a contrast parameter
% this allows the distribution to be shifted without clipping or moving the extrema
FG = imlnc(FG,'independent','g',2.2,'k',0.6);
% apply FG as a displacement map
% you may want to adjust or modify FG and scalings to suit
BG = displace(BG,[1.5 1.5],'xmap',FG,'ymap',FG,'edgetype','replicate');
% blend the images using some blend mode
%R = imblend(FG,BG,1,'overlay',0.8);
%R = imblend(FG,BG,1,'grainmerge',1);
%R = imblend(FG,BG,1,'scaleadd',0.5);
R = imblend(FG,BG,1,'contrast',0.5);
Why is the FG image shifted to be centered about 50% gray?
Blend modes like 'overlay', 'soft light', etc are members of a category of (often misleadingly-named) bidirectional modes. They can both lighten and darken the BG image depending on the content of the FG image. These modes have a neutral response (i.e. R = BG) when FG = 50%. Shifting the FG to have a centered distribution means it will roughly lighten and darken in equal amounts.
Why are there four ouputs images? Which is the right one?
The simple answer is that there are four images to show that there is no right one. Most PS tutorials will probably suggest to use 'overlay', because that's the hammer PS has at hand. A GIMP tutorial might suggest layering multiple 'overlay' layers (because GIMP 'overlay' is actually a permanent bug). Another GIMP tutorial might suggest to use 'grain merge' and then reduce the opacity.
MIMT imblend() leaves that decision up to you. You can use 'overlay' or 'grain merge' or any other bidirectional mode you want. Note that most of these modes are also adjustable, so workarounds like stacking duplicate layers or muting blown-out results by abusing opacity aren't necessary.
The last two modes are different. While the others are a simple function of FG, BG, and the scalar adjustment parameter, 'scaleadd' and 'contrast' depend on the mean color of the FG image. While the neutral response of 'grainmerge' is fixed at FG = 0.5, the neutral response of 'scaleadd' is at mean(FG). In these two cases, the whole task of centering the FG histogram is typically unnecessary.
The comparison here is apropos, since 'scaleadd' is essentially an adjustable version of 'grainmerge' with (default) mean-centering behavior. They both have roughly the same intended purpose.
The synopsis and this PDF constitute a fair description of the modes you have available.
  2 Commenti
C0ppert0p
C0ppert0p il 1 Apr 2023
The more wrinkled paper is, the more it's diminensionality would change. I was wondering is this process can alter the geometry of the paper as well?
DGM
DGM il 1 Apr 2023
Modificato: DGM il 11 Gen 2024
The geometry (height, width) of the image won't be changed, but the area that it covers may change. In the given example, the 'edgetype' option is set to 'replicate' to emulate GIMP behavior, but if it were set to a color tuple, you would see places where the image content pulls away from the image border as it "folds". The same can be done with IPT imwarp().
FG = imread('crumpledpapersmall.jpg');
BG = imread('peppers.png');
% prepare FG and match geometry
FG = rgb2gray(FG);
FG = imresize(FG,imsize(BG,2));
% shift the distribution of FG to be roughly centered about 50% gray
% here, imlnc() applies a nonlinear curve using gamma and a contrast parameter
% this allows the distribution to be shifted without clipping or moving the extrema
FG = imlnc(FG,'independent','g',2.2,'k',0.6);
% apply FG as a displacement map
% you may want to adjust or modify FG and scalings to suit
scale = [1 1]*5;
BG = displace(BG,scale,'xmap',FG,'ymap',FG,'edgetype',[0 1 0]);
% blend the images using some blend mode
R = imblend(FG,BG,1,'scaleadd',0.5);
imshow2(R,'invert')
That said, this still doesn't really emulate the way an inelastic membrane would change shape as it folds.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by