希尔伯特曲线
新方案已更新:https://blog.csdn.net/qq_39464369/article/details/90210366 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190513162218655.?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDY0MzY5,size_16,color_FFFFFF,t_70)
希尔伯特曲线的构造方法:
构造初始形状 把已有图形缩小4倍(对应坐标缩小2倍),放在左下角 将缩小图逆时针旋转90度放在右下角 左右镜像对称 用3条单位线段把4部分连接起来 H为阶数,上图H=2 等分数 :n=2^(H-1) -1 最大边长:SIZE 边长:eg=(1/2)^ H *SIZE 边界宽度 : bd=eg/2
希尔伯特曲线代码
public class Hilbert{
final int SIZE=400;
private int rank=1;
boolean[][] data=new boolean[SIZE][SIZE];
public void h1() {
for(int i=(int) (0.25*SIZE)-1;i
data[j][(int) (0.75*SIZE)]=true;
}
for(int i=(int) (0.25*SIZE)-1;i
for(int i=a;i
data[i][j]=true;
}
}
}
public boolean[][] narrow() {
boolean[][] array=new boolean[SIZE/2][SIZE/2];
for(int i=0;i
if(data[i][j]||data[i][j+1]||data[i+1][j]||data[i+1][j+1]) {
array[i/2][j/2]=true;
}
}
}
return array;
}
public void grow() {
boolean[][] nar = narrow();
for(int i=0;i
data[i][j+SIZE/2]= nar[i][j];
}
}
//旋转放置于左上角
boolean[][] tran = transposition( nar,false);
for(int i=0;i
data[i][j]=tran[i][j];
}
}
//左右镜像对称
for(int i=0;i
data[SIZE-i-1][j]=data[i][j];
}
}
++rank;
int n=(int)( Math.pow(2,rank-1))-1;
int eg=(int)( Math.pow(0.5,rank)*SIZE);
int bd=eg/2;
line(bd,bd+n*eg,bd,bd+n*eg+eg);
line(bd+n*eg,bd+n*eg+eg,bd+n*eg+eg,bd+n*eg+eg);
line(bd+2*n*eg+eg,bd+n*eg,bd+2*n*eg+eg,bd+n*eg+eg);
}
//key为true时关于右倾对角线对称
//key为false时关于左倾对角线对称
public boolean[][] transposition(boolean[][] array,boolean key){
int size=array.length;
boolean[][] tran = new boolean[size][size];
for(int i=0;i
if(key) {
tran[i][j]=array[j][size-1-i];
}else{
tran[i][j]=array[j][i];
}
}
}
return tran;
}
}
希尔伯特曲线展示
public class Test extends Application {
final int SIZE=400;
WritableImage writ =new WritableImage(SIZE, SIZE);
PixelWriter pw=writ.getPixelWriter();
Color color=Color.valueOf("#63B8FF");
Hilbert hi=new Hilbert();
public static void main(String[] args) {launch();}
public void map() {
for(int i=0;i
if(hi.data[i][j]) {
pw.setColor(i,j,color );
}
}
}
}
public void start(Stage primaryStage) throws Exception {
Pane pane=new Pane();
hi.h1();
hi.grow();
// hi.grow();
// hi.grow();
// hi.grow();
map();
ImageView view = new ImageView(writ);
pane.getChildren().add(view);
primaryStage.setScene(new Scene(pane));
primaryStage.setWidth(420);
primaryStage.setHeight(450);
primaryStage.setTitle("Hilbert");
primaryStage.show();
}
}
H=1
![在这里插入图片描述](https://img-blog.csdnimg.cn/2019051316500175.?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDY0MzY5,size_16,color_FFFFFF,t_70)
H=2
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190513164928662.?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDY0MzY5,size_16,color_FFFFFF,t_70)
H=3
![在这里插入图片描述](https://img-blog.csdnimg.cn/201905131650253.?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDY0MzY5,size_16,color_FFFFFF,t_70)
H=4
![在这里插入图片描述](https://img-blog.csdnimg.cn/2019051316504443.?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDY0MzY5,size_16,color_FFFFFF,t_70)
H=5
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190513165110289.?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDY0MzY5,size_16,color_FFFFFF,t_70)
错误分析
图形连接错误的原因在于缩小处理时因整型除法运算会使得位置偏移,比如(35,40)缩小变换后(18,20),并且边长也会改变。在H=4时效果较好。
这里使用到池化(Pooling)技术: 池化可以将一幅大的图像缩小,同时又保留其中的重要信息。通常情况下,池化都是22大小,就是取输入图像中22大小的块中的最大值,作为结果的像素值,相当于将原始图像缩小了4倍
有空换一种方法避免整型带来的误差。
解决办法已更新:https://blog.csdn.net/qq_39464369/article/details/90210366
|