Page 1 of 2

How to make reflected Image thumbnails

Posted: 2007-09-25T09:37:21-07:00
by Isozen
Hi,

I'm a french beginner with ImageMagick and I need your help. I'm trying to make a reflected image like coverflow does in iTunes with your Artwork. You can find a sample of the desired result here http://images.apple.com/ipod/red/images ... 070905.png.

Thanks.

Re: How to make reflected Image thumbnails

Posted: 2007-09-25T17:49:10-07:00
by anthony
The angling requires a perspective distort.

The reflection is easiest done before the distort, by flipping the image over
and applying a transparency gradient, then appending the result to the bottom of the original image.

Basically, try to generate each aspect of the resulting image one piece at a time.

All the techniques are in IM Examples.

Re: How to make reflected Image thumbnails

Posted: 2007-09-26T00:58:13-07:00
by Isozen
Thanks for your answer. I will try this.

Re: How to make reflected Image thumbnails

Posted: 2007-09-26T09:09:22-07:00
by Bonzo
I had had the similar thoughts to you Anthony :lol:

My code is a mishmash of another example I tried. One thing I had problems with before doing a similar distort is that what ever I tried I could not get the -fx "p{v*w,j}" to work horizontaly I had to turn it vertical to distort it then rotate it back !

Image

Code: Select all

convert House.jpg -flip temp.jpg

convert -size 300x600 gradient:none-white gradient_fx_linear.png 

convert temp.jpg gradient_fx_linear.png -gravity south -composite temp3.jpg 

convert House.jpg temp3.jpg -append temp1.jpg

convert temp1.jpg -resize 566x852 -rotate 270 -bordercolor white -border 10x10 src_border2.bmp 

convert ../new_imagemagick/original_images/map_p_trapezoidal1.png -resize 566!x852! temp_mask2.png 

convert -size 660x500 -background white src_border2.bmp temp_mask2.png -fx "p{v*w,j}" temp2.bmp 

convert temp2.bmp -rotate 90 -resize 283!x426! -trim output_reflect.jpg
As I say the code is a real mess but at least it proves the principle.

Re: How to make reflected Image thumbnails

Posted: 2007-09-26T16:10:24-07:00
by anthony
The latest IM has new distort options, as detailed on IM examples
http://www.imagemagick.org/Usage/distorts/#distort
However the coordinate handling is NOT settled at this time and will probably be modified in the next couple of point releases to allow better handling of more than a minimal number of coordinates for possible future use in automatic image registration and panorama photo composites.

Of course I have a stack of research papers with lots of other distorts still to implement too. :lol:

Re: How to make reflected Image thumbnails

Posted: 2007-09-26T16:19:19-07:00
by anthony
Bonzo wrote:I could not get the -fx "p{v*w,j}" to work horizontaly I had to turn it vertical to distort it then rotate it back !
You will need to change or generate a the trapezoidal map as well as the fx distortion lookup for horizontal use as well. Otherwise you need to get really fancy with your image lookup by rescaling the i,j coordinates when mapping them from the source image (and its size) to the distortion map image (and a different size).

Also, as you did not give the formula you used to generate the image...
../new_imagemagick/original_images/map_p_trapezoidal1.png
The user currently can't use you script! :-)

Re: How to make reflected Image thumbnails

Posted: 2007-09-27T05:15:40-07:00
by Bonzo
Messing about over lunch I have lost my old image. Here is one using the distort method; is a lot quicker and easer than the previous FX method.

Image

Code: Select all

<?php

// Make an inverted copy of the original
exec("convert ../original_images/House.jpg -flip temp.jpg");

// Make a gradiant - transparent to white
exec("convert -size 300x600 gradient:none-white gradient_fx_linear.png ");

// Put the gradiant over the iverted image
exec("convert temp.jpg gradient_fx_linear.png -gravity south -composite temp3.jpg ");

// Join the two images together
exec("convert ../original_images/House.jpg temp3.jpg -append temp1.jpg");

// Draw the red outline - just to confirm area to distort
exec("convert temp1.jpg -draw 'fill none stroke red polygon 0,0 0,425, 282,425, 282,0' before.jpg ");

// Draw the blue outline to show the distortion
exec("convert temp1.jpg -draw 'fill none stroke blue polygon 0,0 0,425, 282,325, 282,100' after.jpg");

// Carry out the distortion
exec("convert temp1.jpg -matte -background white -virtual-pixel background -distort Perspective '0,0 0,425, 282,425, 282,0, 0,0 0,425, 282,325, 282,100' output_reflect3.jpg");
?>
ImageImage

Re: How to make reflected Image thumbnails

Posted: 2007-09-27T19:05:39-07:00
by anthony
I would just make one small warning. The order of the coordinates in perspective is probably going to change from, the order...

Code: Select all

     u1,v1  u2,v2  u3,v3  u4,v4     x1,y1 x2,y2  x3,y3   x4,y4
to

Code: Select all

     u1,v1 x1,y1   u2,v2  x2,y2    u3,v3  x3,y3   u4,v4  x4,y4 .....
sometime the next few IM point releases...

The reason is that I am installing a 'least squares fit' which will allow you to give more than the 4 minimal coordinates you would normally need.

This change is for a number of reasons.
  • it defines links src and destination coordinates that refer to each other
    which makes it a lot easier when editing and adjusting the coordinates.
  • coordinates could also then come from a text file mapping of one coodrinade change per line.
  • second it means you can think of the coordinates as any points, not just a
    specific quadrilateral. For example a triangle with a center point is another 4 point representation that can be used.
  • and finally, the main reason... you can use a larger list of automatically determined points (from an image registration). Say 100 or more coordinates!
  • This is not just not just for perspectitve but for even higher level polynomial distortions of coordinates, such as barrel/pincussion distortions (corrections), and posibly future spline or triangular mesh warps (think movie transformations!)
  • more points of registration also allows your to more exactly define the distortion beyond normal pixel resolution, and the posiblity of automatically deleting 'large error' coordinates.
  • Finallly the current (old) method was just something that seemed to be good when I was first proto-typing the perspective transform using -fx. It was never really thought out very well.
If its any consolation, I have a lot of examples that also need changing.

Re: How to make reflected Image thumbnails

Posted: 2007-10-03T04:15:55-07:00
by richo
I am trying to do the same thing like original author of this thread.
Look at his image.
Important is that the shadow is not complete image just a part.
I even do not need that image is turned.
I like to create just shadow of the image as if image would be placed on bottom edge on dark (black) reflective table and light position from top and little front.
I did try povray to render such a scene, but I believe imagemagick can do it faster and better.

As I know only base of imagemagick I would really appreciate help.
Especially how do you manage that the reflection of the image reflects only let say bottom 20% of the image.

Thank you very much for your help.

--
richo
http://www.richard-vanek.eu/

Re: How to make reflected Image thumbnails

Posted: 2007-10-03T10:08:41-07:00
by Bonzo
Not quite sure what you want exactly; try the code out and display each image for each line as you go. That way you will see what is creating each effect.

I assume you just need this part of the code.

Code: Select all

<?php

// Make an inverted copy of the original
exec("convert ../original_images/House.jpg -flip temp.jpg");

// Make a gradiant - transparent to white
exec("convert -size 300x600 gradient:none-white gradient_fx_linear.png ");

// Put the gradiant over the iverted image
exec("convert temp.jpg gradient_fx_linear.png -gravity south -composite temp3.jpg ");

// Join the two images together
exec("convert ../original_images/House.jpg temp3.jpg -append temp1.jpg"); 


How much of the reflected image is shown depends on the gradiant position. The gradiant can also be rotated and this would give the effect of the light coming from a different angle ?

Change the gradiant to this.

Code: Select all

// Make a gradiant - transparent to black
exec("convert -size 300x600 gradient:none-black gradient_fx_linear.png ");

Re: How to make reflected Image thumbnails

Posted: 2007-10-03T19:59:39-07:00
by anthony
richo wrote:Important is that the shadow is not complete image just a part.
The about of the reflection and even how transparent it becomes is basically adding the right type of gradient to the reflected images alpha/matte channel.

Bonzo did the right thing for an initial result, used a linear gradient. You probably want to either adjust the slope of that gradient to make it fully transparent faster, OR use something like a -sigmodial-contrast on the gradient (before it is added) to make it fall off very fast but then slow down as it approaches full transparency.

It is only a matter of tweeking to get exactly what you want.


How about posting a image of your results?

Re: How to make reflected Image thumbnails

Posted: 2007-10-04T05:48:45-07:00
by richo
I will be working on it tonight.
Here is the effect what I like to create.
You can see that image is not really reflected on bottom, just borders.
I like make it better with a little reflection.

Image

Re: How to make reflected Image thumbnails

Posted: 2007-10-04T11:18:08-07:00
by Bonzo
Image
This will do part of what you want ( looks better on a black background ).

Code: Select all

// Change my image to black and white and add a border
exec("convert House.jpg -colorspace Gray -bordercolor white -border 10x10 temp1.png");

// Create reflected image and crop to retain the bottom part of the image; also add a black border to the top and bottom of the image to space them out when joined.
exec("convert ( temp1.png -flip -bordercolor black -border 0x5 ) -crop 303x70+0+0 temp2.png");

// Make a gradiant - transparent to black
exec("convert -size 303x500 gradient:none-black gradient_fx_linear.png ");

// Put the gradiant over the inverted image
exec("convert temp2.png gradient_fx_linear.png -gravity south -composite temp3.png");

// Join the two images together
exec("convert temp1.png temp3.png -append temp4.png"); 
The shadow/gradiant at the bottom of your photo will take some work; you can look at Anthonys examples and see if you can work out how to do what you want http://www.imagemagick.org/Usage/canvas/#gradient Once you get your method sorted you should be able to use it on all your images.

Re: How to make reflected Image thumbnails

Posted: 2007-10-04T11:21:28-07:00
by richo
Is it possible to get size of image automatically so I can define for example 20% from it in next command?

Re: How to make reflected Image thumbnails

Posted: 2007-10-04T12:19:26-07:00
by Bonzo
I work with php and you can use getimagesize(), there may be otherways of doing it but how are you using your code ?