1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| function frame=motif2frame(motif,frame,x,y,scale,mask)
% motif : image 'source'
% frame : image 'destination'
% x,y : coordonnées des 4 sommets de la 'source' dans la 'destination'
% scale : paramètre d'échelle
% mask : masque 'destination' des pixels à ne pas modifier
[hIn,wIn]=size(motif);
xIn=[1 wIn wIn 1];
yIn=[1 1 hIn hIn];
xIn=wIn/2+scale*(xIn-wIn/2);
yIn=hIn/2+scale*(yIn-hIn/2);
tForm=cp2tform([xIn' yIn'],[x' y'],'projective');
[motifTransform,xData,yData]=imtransform(motif,tForm,'Fill',-1);
[hOut,wOut]=size(motifTransform);
xOut=fix(xData(1));
yOut=fix(yData(1));
dxOut=xOut:xOut+wOut-1;
dyOut=yOut:yOut+hOut-1;
pos=find(mask(dyOut,dxOut)==1);
if (length(pos))
motifTransform(pos)=-1;
end
pos=find(motifTransform~=-1);
for p=1:3
frameCut=frame(dyOut,dxOut,p);
if (length(pos))
frameCut(pos)=uint8(motifTransform(pos));
end
frame(dyOut,dxOut,p)=frameCut;
end |
Partager