Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Symmetrical Images

Subject: Symmetrical Images

From: Jessica

Date: 22 Mar, 2008 23:21:02

Message: 1 of 6

Hi,

I wanted to know if anyone knows whether it is possible to
create symmetrical images. For example, I would like to be
able to open a photograph of a person's face and make a
symmetrical image of one half of the face so that the
result would be a face that is perfectly symmetrical.

Thanks!

Jessica

Subject: Symmetrical Images

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 22 Mar, 2008 23:38:11

Message: 2 of 6

In article <fs448u$c7h$1@fred.mathworks.com>,
Jessica <jyorzinski@ucdavis.edu> wrote:

>I wanted to know if anyone knows whether it is possible to
>create symmetrical images. For example, I would like to be
>able to open a photograph of a person's face and make a
>symmetrical image of one half of the face so that the
>result would be a face that is perfectly symmetrical.

Yes, of course.

B = A([1:C C-1:-1:1], :); %horizontal symmetry around y=C
B = A(:, [1:C C-1:-1:1], :); %vertical symmetry around x=C

You can impose a symmetry around any line, but if the line
is not horizontal or vertical or 45 degree diagnonal, then you
would need to interpolate the pixels along the line and in the
reflected image.

Locating the appropriate line to impose the symmetry around is
a more difficult problem ;-)
--
  "To burn always with this hard, gem-like flame, to maintain this
  ecstasy, is success in life." -- Walter Pater

Subject: Symmetrical Images

From: ImageAnalyst

Date: 23 Mar, 2008 00:03:23

Message: 3 of 6

On Mar 22, 7:21=A0pm, "Jessica " <jyorzin...@ucdavis.edu> wrote:
> Hi,
>
> I wanted to know if anyone knows whether it is possible to
> create symmetrical images. For example, I would like to be
> able to open a photograph of a person's face and make a
> symmetrical image of one half of the face so that the
> result would be a face that is perfectly symmetrical.
>
> Thanks!
>
> Jessica


-----------------------------
Jessica:
Well there are two issues here:
1) Where is the line dividing the two halves, and how is it determined
(manually or automatically), and
2) How do you do the flipping?

Please answer 1.
Then assuming you have the dividing line, it may not lie along a
perfectly vertical column - it may be at a slant. Therefore I suggest
you go down the dividing line one pixel at a time taking perpendicular
profiles using improfile. Then flip one of the sides over (which ever
side you want to duplicate). Then write it to an output image at the
same location. I assume you know how to flip half the profile line.
If not, it's something like:
clc;
fullFace=3D[1:11] % Macro works for either even or odd # of elements.
% Use improfile() to get the actual fullFace array.
width =3D length(fullFace)
halfWidth =3D floor(width/2)
leftFace =3D fullFace;
leftFace(1:halfWidth) =3D fullFace(width:-1:(width-halfWidth+1))
rightFace =3D fullFace;
rightFace((width-halfWidth+1):width) =3D fullFace(halfWidth:-1:1)

Make sure you started with a profile that had the same number of
points on both sides of the dividing line. That is, your profile is
symmetric about your dividing line.
Regards,
ImageAnalyst

Subject: Symmetrical Images

From: Jessica

Date: 25 Mar, 2008 03:36:02

Message: 4 of 6

ImageAnalyst <imageanalyst@mailinator.com> wrote in message
<8c9e6538-712d-44eb-b004-
bf6edd350d54@a1g2000hsb.googlegroups.com>...
> On Mar 22, 7:21=A0pm, "Jessica " <jyorzin...@ucdavis.edu>
wrote:
> > Hi,
> >
> > I wanted to know if anyone knows whether it is possible
to
> > create symmetrical images. For example, I would like to
be
> > able to open a photograph of a person's face and make a
> > symmetrical image of one half of the face so that the
> > result would be a face that is perfectly symmetrical.
> >
> > Thanks!
> >
> > Jessica
>
>
> -----------------------------
> Jessica:
> Well there are two issues here:
> 1) Where is the line dividing the two halves, and how is
it determined
> (manually or automatically), and
> 2) How do you do the flipping?
>
> Please answer 1.
> Then assuming you have the dividing line, it may not lie
along a
> perfectly vertical column - it may be at a slant.
Therefore I suggest
> you go down the dividing line one pixel at a time taking
perpendicular
> profiles using improfile. Then flip one of the sides
over (which ever
> side you want to duplicate). Then write it to an output
image at the
> same location. I assume you know how to flip half the
profile line.
> If not, it's something like:
> clc;
> fullFace=3D[1:11] % Macro works for either even or odd #
of elements.
> % Use improfile() to get the actual fullFace array.
> width =3D length(fullFace)
> halfWidth =3D floor(width/2)
> leftFace =3D fullFace;
> leftFace(1:halfWidth) =3D fullFace(width:-1:(width-
halfWidth+1))
> rightFace =3D fullFace;
> rightFace((width-halfWidth+1):width) =3D fullFace
(halfWidth:-1:1)
>
> Make sure you started with a profile that had the same
number of
> points on both sides of the dividing line. That is, your
profile is
> symmetric about your dividing line.
> Regards,
> ImageAnalyst

Hi,

Thanks for looking this issue over. I would hope to
manually draw a straight line down the middle of the face.

Thanks,
Jessica

Subject: Symmetrical Images

From: Alessandro Mura

Date: 25 Mar, 2008 12:27:02

Message: 5 of 6

>
> Hi,
>
> Thanks for looking this issue over. I would hope to
> manually draw a straight line down the middle of the face.
>
> Thanks,
> Jessica
>

Hi,
hope this helps.
I've tried for jpeg images only, btw.
Just load an image and select two points (to determine
the line)..

Alessandro Mura
www.alessandromura.it

close all
function mirrowimage
 % bowse an image
 [filenome,pathnome]=uigetfile({'*jpg'; '*.tif'; '*.png'});
 
% read it
im=imread([pathnome filenome ]);


nx=size(im,1);
ny=size(im,2);
nrgb=size(im,3);
 
% show it
image(im)
axis image



% select 2 points on the screen
[xp,yp]=ginput(2);




% creates a coordinate system
[y,x]=ndgrid(1:nx,1:ny);

% calculates the parameters m & q for the line
m=diff(yp)/diff(xp);
q=yp(1)-m*xp(1);


% indexes on the right of the line
[xr,yr]= find(m*x+q > y);


% on the left...after the reflection
yl=floor(2*(-1*m*q+1*m*xr+1*yr)/(1+m^2)-yr);
xl=floor(-2*(-q*1-m^2*xr-m*1*yr)/(1+m^2)-xr);

% to avoid picking points outside the image
j=(xl>0) & (yl > 0) & (yl <= ny) & (xl <= nx) ;


for i=1:nrgb
    ir=xr(j)+(yr(j)-1)*nx+(i-1)*nx*ny;
    il=xl(j)+(yl(j)-1)*nx+(i-1)*nx*ny;
    im(ir)=im(il);
end



image(im)
axis image

% draw a line

hold on
plot(xp,yp,'r--')

Subject: Symmetrical Images

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 25 Mar, 2008 17:59:12

Message: 6 of 6

In article <fsar2m$jdt$1@fred.mathworks.com>,
Alessandro Mura <nospam@alessandro.mura.ifsi-roma.inaf.it> wrote:

>function mirrowimage

>% select 2 points on the screen
>[xp,yp]=ginput(2);
>% creates a coordinate system
>[y,x]=ndgrid(1:nx,1:ny);

>% calculates the parameters m & q for the line
>m=diff(yp)/diff(xp);
>q=yp(1)-m*xp(1);

>% indexes on the right of the line
>[xr,yr]= find(m*x+q > y);

>% on the left...after the reflection
>yl=floor(2*(-1*m*q+1*m*xr+1*yr)/(1+m^2)-yr);
>xl=floor(-2*(-q*1-m^2*xr-m*1*yr)/(1+m^2)-xr);

There are a couple of difficulties with the code:

(1) You do not check for vertical lines, for which diff(xp) would be 0,
leading to a divide by 0 in your code;

(2) If the dividing line is not exactly horizontal or vertical
or diagonal, then the distance from any "source" point to the line
will be a different distance than from the line to the center of
the "reflected" point's coordinate you calculate, so the reflected
image will not be quite symmetric.

Imagine for a moment a "face" with horizontal stripes, and that
you are reflecting the face through a line which is at a slight
angle less than the vertical. Then the reflected image will not
have stripes that lead slightly downward: it will have "glitches"
right at the line of reflection (pixels that are fully coloured
one way or another when they should only be partly coloured),
and it will have "staircase" quantization on the reflected stripes
instead of straight lines.
--
This is a Usenet signature block. Please do not quote it when replying
to one of my postings.
http://en.wikipedia.org/wiki/Signature_block

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us