i don't see where filter(threshold) comes into play here.
i just trundle through the pixels of the picture replacing each pixel with a dot, or whatever, of the correct size for the brightness of the image at that point (lines 29-46 of that sketch).
i also normally cheat and resize the picture and desaturate it outside of the sketch.
// da http://www.analogpixel.org/blog/2012/03/20/msced-334-half-tone/
// Halftonize
// added PDF export / Paolo Bartoli 28.10.2013
PImage img;
int bsize = 5;
boolean offset = true;
import processing.pdf.*;
void setup() {
println( brightness( color(255)));
println( brightness( color(0)));
noStroke();
img = loadImage("DSC_4645.jpg");
size(img.width, img.height);
background(255);
tint(255, 170);
image(img, 0, 0);
noLoop();
beginRecord(PDF, "Halftonize export.pdf");
//filter(POSTERIZE,4);
filter(THRESHOLD);
noTint();
for (int x=0; x < width; x+=bsize) {
for (int y=0; y < height; y += bsize) {
color c = getavg(x, y, bsize);
float b = brightness(c);
int r = 0;
fill(0);
if ( b > 0 && b < 50) {
r = bsize;
}
if ( b > 50 && b < 90) {
r = floor(bsize * .9);
}
if ( b > 90 && b < 130) {
r = floor(bsize * .8);
}
if ( b > 130 && b < 190) {
r = floor(bsize * .4);
}
if ( b > 190 && b < 230) {
r = floor(bsize * .2);
}
if ( b > 230) {
r = 1;
}
if ( offset) {
ellipse(x+bsize, y, r, r);
}
else {
ellipse(x, y, r, r);
}
offset = ! offset;
}
}
println("Finished");
saveFrame("output/output##.jpg");
}
color getavg(int x, int y, int blocksize) {
float r =0;
float g =0;
float b =0;
int count=0;
for (int xx=x; xx < x+ blocksize; xx++) {
for (int yy=y; yy< y +blocksize; yy++) {
r += red( img.get(xx, yy) );
g += green( img.get(xx, yy));
b += blue( img.get(xx, yy));
count++;
}
}
return color( r/count, g/count, b/count);
}
void draw() {
endRecord();
}
Unfortunately I get a "No filter() for PGraphicsPDF" error... :-(
I just deleted **filter(threshold) ** from the above sketch and it works...
Still a lot of work to do... I'm just learning Processing on the way, learn by doing :-)
My output now is color JPG bitmap and b/w PDF.
Why PDF comes out in b/w??
Answers
Already found something myself here: http://www.analogpixel.org/blog/2012/03/20/msced-334-half-tone/
and here http://forum.processing.org/one/topic/converting-images-to-halftone-in-processing.html
Analog Pixel sketch works great, in B/W. Next I'll try to get some color...
Also here, in color !
http://www.openprocessing.org/sketch/79607
that last isn't really half-toning it's just replacing square pixels with averaged rounded ones.
b&w halftone changes the dot size depending on brightness.
colour halftoning does the same but with three or four different channels, one for each primary colour*, at angles to each other.
http://en.wikipedia.org/wiki/Halftone
Thanks for your input Koogs.
I'm trying in the meantime to understand how these sketches works, in order to make my own stuff.
First of all, I'd like to have PDF output, no bitmaps. This works easily in most cases, but not when you're using Processing
filter(THRESHOLD)
like in this sketch: http://www.analogpixel.org/blog/2012/03/20/msced-334-half-toneHow to integrate PDF output with
filter(THRESHOLD)
. I guess I need a workaround...Why don't you post your attempt? :-L
i don't see where filter(threshold) comes into play here.
i just trundle through the pixels of the picture replacing each pixel with a dot, or whatever, of the correct size for the brightness of the image at that point (lines 29-46 of that sketch).
i also normally cheat and resize the picture and desaturate it outside of the sketch.
You should avoid asking the same question on several threads...
right GoToLoop, here we are:
Unfortunately I get a "No filter() for PGraphicsPDF" error... :-(
Koogs, you're right.
I just deleted **filter(threshold) ** from the above sketch and it works... Still a lot of work to do... I'm just learning Processing on the way, learn by doing :-)
My output now is color JPG bitmap and b/w PDF. Why PDF comes out in b/w??
where are you setting the fill colour? and to what?
8)