Here is some quick hack to a blob detect processing sketch to export a pdf when pressing a touch ("r").
The pdf is then easily converted to svg by any of your vector apps.
You will need the peasy and blobDetection libraries installed.
input:

output:

Caveat: the memory need hogging is truly humungous. Do increase reserved memory in the preferences to 1GB or more.
Keep the images small, as well as the number of iso-curves. The example posted has already "too many".
have fun!
import blobDetection.*;
import peasy.*;
import processing.pdf.*;
PeasyCam cam;
PImage img;
float levels = 10; // number of contours
float factor = 1; // scale factor
float elevation = 30; // total height of the 3d model
float colorStart = 0; // Starting degree of color range in HSB Mode (0-360)
float colorRange = 50; // color range / can also be negative
boolean record; // to record a pdf
// Array of BlobDetection Instances
BlobDetection[] theBlobDetection = new BlobDetection[int(levels)];
void setup() {
size(1000,800,P3D);
img = loadImage("input.gif"); // heightmap (about 250×250px)
cam = new PeasyCam(this,200);
colorMode(HSB,360,100,100);
//Computing Blobs with different thresholds
for (int i=0 ; i<levels ; i++) {
theBlobDetection[i] = new BlobDetection(img.width, img.height);
theBlobDetection[i].setThreshold(i/levels);
theBlobDetection[i].computeBlobs(img.pixels);
}
}
void draw() {
background(0);
if (record) {
beginRaw(PDF, "output.pdf");
}
translate(-img.width*factor/2,-img.height*factor/2);
for (int i=0 ; i<levels ; i++) {
translate(0,0,elevation/levels);
drawContours(i);
}
if (record) {
endRaw();
record = false;
}
}
// Hit 'r' to record a single frame
void keyPressed() {
if (key == 'r') {
record = true;
}
}
void drawContours(int i) {
Blob b;
EdgeVertex eA,eB;
for (int n=0 ; n<theBlobDetection[i].getBlobNb() ; n++) {
b=theBlobDetection[i].getBlob(n);
if (b!=null) {
stroke((i/levels*colorRange)+colorStart,100,100); // coloring the contours
for (int m=0;m<b.getEdgeNb();m++) {
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null)
line(
eA.x*img.width*factor, eA.y*img.height*factor,
eB.x*img.width*factor, eB.y*img.height*factor
);
}
}
}
}
|