【发布时间】:2014-07-09 06:31:21
【问题描述】:
大家好,我必须转换这张图片:
在这个:
在 Java 中。
这是我的代码:
double Cx =original_img.width()/2;
double Cy =original_img.height()/2;
int rho,theta;
for (int i=0;i<img.getHeight();i++){
for(int j=0;j<img.getWidth();j++){
rho = (int)(Math.sqrt(Math.pow(i-Cx,2) + Math.pow(j-Cy,2)));
theta = (int)(Math.atan2((j-Cy),(i-Cx)));
int color;
try{
color = img.getRGB((int)rho, (int)theta);
}catch(Exception e){
color = 0;
}
int alpha = (color>>24) & 0xff;
int red = (color & 0x00ff0000) >> 16;
int green = (color & 0x0000ff00) >> 8;
int blue = color & 0x000000ff;
int pixel = (alpha << 24) | (red << 16) | (green << 8) | blue;
img2.setRGB(rho, theta, pixel);
System.out.println("point: "+rho+" "+theta);
}
}
怎么了? 我还没有在java中找到一个简单而好的Log-Polar变换。
我的步骤是:
1) 拍摄原始图像 (original_img)
2) 在图像的行和列上循环
3) 计算 rho 和 theta(是新像素的新 X 和 Y 坐标,对吧?)
4) 获取坐标 (rho,theta) 处的颜色像素
5) 创建新像素并设置新坐标。
什么遗漏或错误?
谢谢。
【问题讨论】:
-
是javacv还是opencv的java api?
-
笛卡尔坐标如何应用于图像?通过图像的尺寸?你到底想达到什么目的?笛卡尔和极坐标是二维的,图像通常被认为是多维的,那又如何?
-
“笛卡尔坐标如何应用于图像”是什么意思?我用过: Mat original_img = Highgui.imread(file.getAbsolutePath());通过文件读取图像
-
顺便说一句,Core.cartToPolar
标签: java image opencv processing