Page 1 of 1

Get Pixels from one image and set them in one new image

Posted: 2010-08-28T08:09:44-07:00
by occurred
Hello,

I'm trying to convert an omnidirectional image to a "normal" image ( panorama image doughnut stretching ).

Here is my Java/Groovy Code:

Code: Select all

import java.awt.image.BufferedImage
import javax.imageio.ImageIO

String inFile = '/myPath/webcast.jpg'
BufferedImage img = ImageIO.read(new File(inFile));
int width = 1200
int height = 300
double r1 = 260
double r2 = 1160
double offx = 1278
double offy = 1280
double pi = Math.PI
int ix = 0
int iy = 0
int y = 0
int x = 0
double al = 0
double kat = 0
int color = 0
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)

for (y = image.getHeight(); y > 0; y--) {

	for (x = 0; x < image.getWidth(); x++) {

		//calculate the X/Y position of the pixel in the source
		al = (x / (width - 1)) * 2 * pi;
		kat = r1 + (((y - 1) / (height)) * (r2 - r1));

		ix = offx + kat * Math.cos(al);
		iy = offy + kat * Math.sin(al);

		// get one pixel
		color = img.getRGB(ix, iy)

		// set one pixel
		image.setRGB(x, height - y, color)
	}
}

File f = new File('/myPath/test.jpg');

ImageIO.write(image, "jpg", f)

The image for testing this can be found here:
http://img836.imageshack.us/img836/9207/webcast.jpg

This is absoulutely working, but the result is not perfect.

In short words:
I'm taking from one existing image pixel by pixel and place them in a new empty image.

Because of image quality and performance issues I'll change my existing code and will add ImageMagick to it.
I think I'll use the command line, because I read about performance issues with JMagick.

My questions are:
  • How is this possible with ImageMagick to do it like in my example and getPixels and setPixels?
    Do I've to use crop, but how to write it then in a new image?
cheers
Charlie

Re: Get Pixels from one image and set them in one new image

Posted: 2010-08-28T10:18:36-07:00
by fmw42
in command line there is -fx that can do many mathematical transforms and place pixels from one image to another.

But your picture looks like a simple case of converting a fisheye to panorama. This can be done with my script fisheye2pano or even better now with IM function -disort polar/depolar.

see my scripts below or look up the IM function at http://www.imagemagick.org/Usage/distorts/#depolar

Re: Get Pixels from one image and set them in one new image

Posted: 2010-08-28T13:01:25-07:00
by el_supremo
Try this:

Code: Select all

convert webcast.jpg -gravity center -extent 5112x2560 +distort DePolar "1280 0 2556,1280 90" -resize 33% -flip webcast_depolar.jpg
Pete

Re: Get Pixels from one image and set them in one new image

Posted: 2010-08-29T19:06:37-07:00
by anthony
While distort depolar will do most of the work. The 'angulr height' will not be corrected.

Fred script while not using -distort depolar does correct this angular height.

Sorry I have not had any time to implement proper 'fisheye' distortion methods (either direction)
Though it is open to some programmer to add it! (look at source file "magick/distort.c")

Re: Get Pixels from one image and set them in one new image

Posted: 2010-08-29T19:20:02-07:00
by fmw42
anthony wrote:While distort depolar will do most of the work. The 'angulr height' will not be corrected.

Fred script while not using -distort depolar does correct this angular height.

Sorry I have not had any time to implement proper 'fisheye' distortion methods (either direction)
Though it is open to some programmer to add it! (look at source file "magick/distort.c")

See my last example at http://www.fmwconcepts.com/imagemagick/ ... /index.php, which uses -distort depolar, then corrects that aspect ratio with -resize, then corrects the perspective with another script. Makes it faster than running my original script that makes heavy use of -fx.