Get the App
SLTechnology News&Howtos  ›  Development  › 

How to generate site poster special effects with one click of Matlab

Shulou Source: shulou.com Published: 2022-06-01 02:26:16 10月03日 Update

This article introduces the relevant knowledge of "how to use Matlab to generate special effects on construction site posters with one click". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

1. use effect

2. Image preparation and import

First of all, there should be two pictures in the folder where the m file is located:

In addition, you need an approximately square image to be placed in the folder together, and then import and preliminarily process the image through the following code (select the curtain part and the color removal code, slide left and right):

bkgPic=imread('bkg.jpg'); % background image screenPic=bkgPic(190:555,(190:555)+160,:);% curtain area image grayscreenPic=rgb2gray(screenPic); % Grayscale Screen Region Picture screenRange=imread ('screenRange.jpg '); % Screen Range Map (used to close screen edge detail)screenRange=rgb2gray(screenRange);forePic=imread ('2048.jpg '); % Pictures to be made into posters

3. image tilt

We can see that the curtain is slightly tilted. In order to make the image closer to the curtain, we tilt the image and adjust it to a size similar to the curtain area:

% foreground picture distortion =============================================================

4. twist permutation

This part refers to the previous part of the cloth map:

% twisted permutation ================================================================= for j=1:size(grayscreenPic,2) goffset=(double(grayscreenPic(i,j))-128)/10; offsetLim1=floor(goffset)+13; offsetLim2=ceil(goffset)+13; sep1=goffset-floor(goffset); sep2=ceil(goffset)-goffset; c1=double(exforePic(i+offsetLim1,j+offsetLim1,:)); c2=double(exforePic(i+offsetLim2,j+offsetLim2,:)); if sep1==0 c=double(exforePic(i+offsetLim1,j+offsetLim1,:)); else c=c2.* sep1+c1.* sep2; end newforePic(i,j,:)=c; endend

5.================================================================= double(grayscreenPic))./ 220);% imshow(newforePic)% old version use this code % newforePicR=double(newforePic(:,:,1)).* double(grayscreenPic)./ 220;% newforePicG=double(newforePic(:,:,2)).* double(grayscreenPic)./ 220;% newforePicB=double(newforePic(:,:,3)).* double(grayscreenPic)./ 220;% newforePic(:,:,1)=newforePicR;% newforePic(:,:,2)=newforePicG;% newforePic(:,:,3)=newforePicB;% newforePic=uint8(newforePic);

6. Edge trimming (matting)

After the top is overlapped, the outside of the curtain is still gray, and the content of the curtain is partially beyond the scope of the curtain. We can trim the curtain with the curtain range map:

% Edge Trim =================================================================(screenRange>20)=newforePicR(screenRange>20);screenPicG(screenRange>20)=newforePicG(screenRange>20);screenPicB(screenRange>20)=newforePicB(screenRange>20);screenPic(:,:,1)=screenPicR;screenPic(:,:,2)=screenPicG;screenPic(:,:,3)=screenPicB;screenPic=uint8(screenPic);

7. Background Image Replacement % Replace background image area with new image =================================================

8. function consPosterbkgPic=imread ('bkg.jpg '); % background image screenPic=bkgPic(190:555,(190:555)+160,:);% curtain area image grayscreenPic=rgb2gray(screenPic); % Grayscale Screen Region Picture screenRange=imread ('screenRange.jpg '); % Screen Range Map (used to close screen edge detail)screenRange=rgb2gray(screenRange);forePic=imread ('2048.jpg '); % Picture to be made into poster % Foreground picture distortion =============================================================([1 -0.02 0;-0.02 1 0; 0 0 1]);forePic=imwarp (forePic,tform);exforePic=imresize(forePic,size(grayscreenPic)+26);% twisted permutation ================================================================= for j=1:size(grayscreenPic,2) goffset=(double(grayscreenPic(i,j))-128)/10; offsetLim1=floor(goffset)+13; offsetLim2=ceil(goffset)+13; sep1=goffset-floor(goffset); sep2=ceil(goffset)-goffset; c1=double(exforePic(i+offsetLim1,j+offsetLim1,:)); c2=double(exforePic(i+offsetLim2,j+offsetLim2,:)); if sep1==0 c=double(exforePic(i+offsetLim1,j+offsetLim1,:)); else c=c2.* sep1+c1.* sep2; end newforePic(i,j,:)=c; endend% orthonormal stack ================================================================= double(grayscreenPic))./ 220);% imshow(newforePic)% old version use this code % newforePicR=double(newforePic(:,:,1)).* double(grayscreenPic)./ 220;% newforePicG=double(newforePic(:,:,2)).* double(grayscreenPic)./ 220;% newforePicB=double(newforePic(:,:,3)).* double(grayscreenPic)./ 220; % newforePic(:,:,1)=newforePicR; % newforePic(:,:,2)=newforePicG; % newforePic(:,:,3)=newforePicB; % newforePic=uint8 (newforePic);% Edge Trim =================================================================(screenRange>20)=newforePicR (screenRange>20);screenPicG (screenRange>20)=newforePicG (screenRange>20);screenPicB (screenRange>20)=newforePicB (screenRange>20);screenPic(:,:,1)=screenPicR;screenPic(:,:,2)=screenPicG;screenPic(:,:,3)=screenPicB;screenPic=uint8 (screenPic);% imshow(screenPic)% Change the background image curtain area to a new image ================================================= If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Screen picture area code background poster range edge content file part replacement site special effects one click generate foreground image folder more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Redmi macOS Apple Xiaomi