Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make the effect of circular photo album with Matlab

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use Matlab to make circular photo album effect", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to use Matlab to make circular photo album effect"!

Running effect

Complete step 1. Picture preparation and import

It is essential to make a photo album with a sufficient number of pictures, otherwise it would be boring for the whole album to have only one picture to repeat back and forth, so we need a folder for pictures. In order to facilitate import, all of them are in jpg format:

Image import code:

Path='.\ album\';% folder path files=dir (fullfile (path,'*.jpg')); picNum=size (files,1); every image under the% traversal path for i=1:picNum fileName = strcat (path,files (I) .name); img = imread (fileName); imgSet. (['pause num2str (I)]) = img;end2. Make a mask layer for each picture for i=1:length (BlockNum)% number of torus layers blockNum=BlockNum (I);% number of pictures per layer Rrange=R (iMagne:);% one layer radius range for j=1:blockNum tempBoard=ones (2401199012401) = = 1; tempBoard=tempBoard& (disMesh > Rrange (1)) & (disMesh ((Jmur1) * 2*pi/blockNum)) & (thetaMeshRrange (1)) & (disMesh ((Jmur1) * 2*pi/blockNum)) & (thetaMesh0) TrueY=find (sum (tempBoard,2) > 0); tempMask=tempBoard (min (TrueY): max (TrueY), min (TrueX): max (TrueX)); x1=YMesh (min (TrueX), min (TrueY)); y1=XMesh (min (TrueX), min (TrueY)); x2=YMesh (max (TrueX), max (TrueY)); y2=XMesh (max (TrueX), max (TrueY)); xdiff=x2-x1; ydiff=y2-y1 Pic=imgSet. (['pause Magnum num2str (tempPic)]); [rows,cols,~] = size (pic); ratio= [ydiff+1,xdiff+1]. / [rows,cols]; newsize=ceil ([rows,cols]. * max (ratio)); offset=floor ((newsize- [ydiff+1,xdiff+1]). / 2); pic=imresize (pic,newsize) Pic=pic (1:ydiff+1) + offset (1), (1:xdiff+1) + offset (2),:); endend4. Drawing and detailed explanation of drawing parameters

Basic parameters:

BlockNum= [7d11];% number of sectors per floor

R = [300670% radius range of the first floor

670pr 1090];% radius range of the second layer

LineColor= [0.98, 0.98, 0.98]

LineWidth=2;% line thickness

We'll talk about the properties of the line later.

The drawing is done directly by using the image function. There is nothing to say about this. If there are not many pictures in the folder, we will use the remainder method to cycle through the previous picture:

TempPic=1;for i=1:length (BlockNum) blockNum=BlockNum (I); for j=1:blockNum tempPic=tempPic+1; tempPic=mod (tempPic-1,picNum) + 1; endend

We found that the edge aliasing is more serious when drawing directly:

It's easy to think of drawing lines to cover up ugliness:

(2*pi+0.001); for i=1:length (BlockNum) blockNum=BlockNum (I); Rrange=R (iMagne:) For j=1:blockNum plot (cos (j*2*pi/blockNum). * Rrange,sin (j*2*pi/blockNum). * Rrange,'Color',lineColor,'LineWidth',lineWidth) end plot (cos (t). * Rrange (1), sin (t). * Rrange (1), 'Color',lineColor,'LineWidth',lineWidth) plot (cos (t). * Rrange (2), sin (t). * Rrange (2),' Color',lineColor,'LineWidth',lineWidth) end

Of course, you can also draw black lines:

All you need is lineColor= [0J 0J 0] or lineColor='k'.

Complete code function ringAlbumBlockNum= [7img 11]; R = [300670; 670 1090]; lineColor= [0.98 album 0.98]; lineWidth=2;path='.\ album\';% folder name files=dir (fullfile (path,'*.jpg')); picNum=size (files,1); every image under the% traversal path for i=1:picNum fileName = strcat (path,files (I) .name); img = imread (fileName); imgSet. Endfig=figure ('units','pixels',... Position', [20 60 560 560],... 'Color', [1 11]); ax=axes (' Units','pixels',... 'parent',fig,... 'Color', [1 11],... 'Position', [560560],... 'XLim', [- 1200, 1200],... 'YLim', [- 1200, 1200],... 'XColor','none',... 'YColor','none'); hold (ax,'on') ax.YDir='reverse';ax.XDir='normal'; [XMesh,YMesh] = meshgrid; disMesh=sqrt (XMesh. ^ 2 + YMesh. ^ 2); thetaMesh=atan2 (YMesh,XMesh) + pi;thetaMesh=thetaMesh (:, end:-1:1); tempPic=1;t=0:0.001: (2*pi+0.001); for i=1:length (BlockNum) blockNum=BlockNum (I); Rrange=R (iMagna:) For j=1:blockNum tempBoard=ones (2401 min 2401) = 1; tempBoard=tempBoard& (disMesh > Rrange (1)) & (disMesh ((jmur1) * 2*pi/blockNum)) & (thetaMesh0); TrueY=find (sum (tempBoard,2) > 0); tempMask=tempBoard (min (TrueY): max (TrueY), min (TrueX): max (TrueX)); x1=YMesh (min (TrueX), min (TrueY)); y1=XMesh (min (TrueX), min (TrueY)) X2=YMesh (max (TrueX), max (TrueY)); y2=XMesh (max (TrueX), max (TrueY)); xdiff=x2-x1; ydiff=y2-y1; pic=imgSet. (['pamphagol num2str (tempPic)]); [rows,cols,~] = size (pic); ratio= [ydiff+1,xdiff+1]. / [rows,cols]; newsize=ceil ([rows,cols]. * max (ratio)) Offset=floor ((newsize- [ydiff+1,xdiff+1])). / 2); pic=imresize (pic,newsize); pic=pic ((1:ydiff+1) + offset (1), (1:xdiff+1) + offset (2),:); image (ax, [x1jue x2], [y1jiny2], pic,'alphaData',tempMask); tempPic=tempPic+1; tempPic=mod (tempPic-1,picNum) + 1 End for j=1:blockNum plot (cos (j*2*pi/blockNum). * Rrange,sin (j*2*pi/blockNum). * Rrange,'Color',lineColor,'LineWidth',lineWidth) end plot (cos (t). * Rrange (1), sin (t). * Rrange (1), 'Color',lineColor,'LineWidth',lineWidth) plot (cos (t). * Rrange (2), sin (t). * Rrange (2),' Color',lineColor,'LineWidth' LineWidth) endend to this I believe you have a deeper understanding of "how to use Matlab to make circular photo album effect". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report