私はblobDetection libraryで処理中で、高さマップから等高線マップを作成しています。 私は現在、各レイヤーをレーザーカットのSVGとしてエクスポートしていますが、スケッチの端にあるブロブは完全ではなく、エッジの頂点は描画されません。ここ処理でスケッチの端にあるBlobのエッジを描画する
が簡単な例である:
- Iで始まる画像は、白領域がブロブ
-
なろう
- SVG出力、エッジを欠いている。
- は海峡を描く0(最小幅または高さ)または1(最大幅または高さ)
- に等しいです。
- 他の多くの条件というコーナーをオーバーラップされたが、そう多くは、私は混乱していますどのように条件を注文するか、または問題にアプローチする方法のアイデア。 大いに助けてください!
import processing.svg.*;
import blobDetection.*;
import peasy.*;
import processing.pdf.*;
PeasyCam cam;
PImage img;
float levels = 10;
BlobDetection[] contours = new BlobDetection[int(levels)];
//Creating array to store the blob objects
ArrayList<Ring> rings = new ArrayList<Ring>();
void setup() {
size(480, 360, P3D);
surface.setResizable(true);
img = loadImage("maptest2.jpg");
surface.setSize(img.width, img.height);
cam = new PeasyCam(this, img.width, img.height, 0, 1500);
colorMode(HSB, 360, 100, 100);
for (int i=0; i<levels; i++) {
contours[i] = new BlobDetection(img.width, img.height);
contours[i].setThreshold(i/levels);
contours[i].computeBlobs(img.pixels);
}
for (int i = 0; i < rings.size(); i++) {
System.out.println("id: " + rings.get(i).getId());
System.out.println("lvl: " + rings.get(i).getLvl());
System.out.println("x: " + rings.get(i).getX());
System.out.println("y: " + rings.get(i).getY());
System.out.println();
}
noLoop();
}
void draw() {
for (int i=0; i<levels; i++) {
beginRecord(SVG, "level-"+i+".svg");
drawContours(i);
println("drew level " + i);
println("saved as: level-"+i+".svg");
endRecord();
println();
if(i == levels-1){
println("finished");
}
}
System.out.println("Number of blobs (rings.size()): " + rings.size());
println();
for (int i = 0; i < rings.size(); i++){
System.out.println("id: " + rings.get(i).getId());
System.out.println("lvl: " + rings.get(i).getLvl());
System.out.println("x: " + rings.get(i).getX());
System.out.println("y: " + rings.get(i).getY());
System.out.println();
}
}
void drawContours(int i) {
Blob b;
EdgeVertex eA, eB;
for (int n=0; n<contours[i].getBlobNb(); n++) {
b=contours[i].getBlob(n);
//Condition for drawing only blobs bigger than 5% of width and 5% of height
if(b.w*width>.05*width && b.h*height>.05*height){
if (b!=null) {
stroke(250, 75, 90);
for (int m=0; m<b.getEdgeNb(); m++) {
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
//This part draws the blobs.
if (eA !=null && eB !=null)
line(
eA.x*img.width, eA.y*img.height,
eB.x*img.width, eB.y*img.height
);
println("eA.x: " + eA.x);
println("eA.y: " + eA.y);
println("eB.x: " + eB.x);
println("eB.y: " + eB.y);
println();
////////////
//Here are my various attempts at drawing these rogue edges!
//I commented them out
/*
//Checking if vertex has a point at x=0
if (b.getEdgeVertexA(m).x == 0 && b.getEdgeVertexB(b.getEdgeNb()).x == 0){
line( b.getEdgeVertexA(0).x*img.width, b.getEdgeVertexA(0).y*img.height,
b.getEdgeVertexA(m).x*img.width, b.getEdgeVertexA(m).y*img.height );
println("////");
println("x making line (scaled 0-1): ");
//println(eA.x, eA.y, eB.x, eB.y);
println( b.getEdgeVertexA(0).x, b.getEdgeVertexA(0).y,
b.getEdgeVertexA(m).x, b.getEdgeVertexA(m).y );
println("////");
}
//Checking if vertex has a point at y=0
if (b.getEdgeVertexA(m).y == 0 && b.getEdgeVertexB(b.getEdgeNb()).y == 0){
line( b.getEdgeVertexA(0).x*img.width, b.getEdgeVertexA(0).y*img.height,
b.getEdgeVertexA(m).x*img.width, b.getEdgeVertexA(m).y*img.height );
println("////");
println("y making line (scaled 0-1): ");
//println(eA.x, eA.y, eB.x, eB.y);
println( b.getEdgeVertexA(0).x, b.getEdgeVertexA(0).y,
b.getEdgeVertexA(m).x, b.getEdgeVertexA(m).y );
println("////");
}
if (b.getEdgeVertexA(m).x == 0 && b.getEdgeVertexB(b.getEdgeNb()).y == 0){
line( b.getEdgeVertexA(0).x*img.width, b.getEdgeVertexA(0).y*img.height, 0, 0 );
println("drew to 0,0");
}
if (b.getEdgeVertexA(m).y == 0 && b.getEdgeVertexB(b.getEdgeNb()).x == 0){
line( b.getEdgeVertexA(m).x*img.width, b.getEdgeVertexA(m).y*img.height, 0, 0 );
println("drew to 0,0");
}
*/
////////////
}
//Adding objects to the rings ArrayList
rings.add(new Ring(String.valueOf(rings.size()+1), (int) i, (double) b.x*100, (double) b.y*100));
}
}
}
}
は今、私は私のコードは、これらのエッジを描画するために任意のコードが含まれていません知っている知っているので、彼らは本当に欠落していないが、私は一種の適切これらを描画するために開始する場所へと失われています。
私は約考えている:任意のブロブを構成する頂点の座標かどうかをチェック
誰でも持っている...スケッチの左上隅にブロブ四肢からのラインがあれば、たとえばブロブは
コードをそのまま試してみましたが、うまくいきませんでした。少し修正してもう一度試してみますが、私は本当に必要なものではないと思います。私が理解するところでは、コードがスケッチの端を越えているかどうかをチェックしますが、高さマップイメージファイルから始めるので、境界線はイメージであり、ブロブは想像力の中でしかエッジを超えません。したがって、実際には、ブロブが完全(閉じていない)かどうかをチェックし、スケッチの端に沿って閉じる必要があります。 – LaVielle