我开发了一种可以帮助你的简单方法.它只是从左到右和从右到左删除叶边界.
唯一的含义是叶面向.我手动旋转输出图像.但是,我认为你应该考虑这个位置的叶子来进行更好的分析.
leaf_rotated.jpg:
leaf_rotated_out.jpg:
源代码:
public class LeafTest {
public static void main(String[] args) {
MarvinImage image = MarvinImageIO.loadImage("./res/leaf_rotated.jpg");
removeBorder(image);
MarvinImageIO.saveImage(image, "./res/leaf_rotated_out.jpg");
}
private static void removeBorder(MarvinImage image){
// left to right
for(int y=0; y
for(int x=0; x
if(image.getIntComponent0(x, y) > 10){
for(int x2=x; x2
image.setIntColor(x2, y, 0,0,0);
}
x=0;
break;
}
}
}
// right to left
for(int y=0; y
for(int x=image.getWidth()-1; x>=0; x--){
if(image.getIntComponent0(x, y) > 10){
for(int x2=x; x2>=0 && x2 > x-40; x2--){
image.setIntColor(x2, y, 0,0,0);
}
x=image.getWidth()-1;
break;
}
}
}
}
}