Get Pixels from one image and set them in one new image
Posted: 2010-08-28T08:09:44-07:00
Hello,
I'm trying to convert an omnidirectional image to a "normal" image ( panorama image doughnut stretching ).
Here is my Java/Groovy Code:
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:
Charlie
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?
Charlie