Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,14 @@
fcn histogram(image){
hist:=List.createLong(256,0); // array[256] of zero
image.data.howza(0).pump(Void,'wrap(c){ hist[c]+=1 }); // byte by byte loop
hist;
}
fcn histogramMedian(hist){
from,to:=0,(2).pow(8) - 1; // 16 bits of luminance
left,right:=hist[from],hist[to];
while(from!=to){
if(left<right){ from+=1; left +=hist[from]; }
else { to -=1; right+=hist[to]; }
}
from
}

View file

@ -0,0 +1,10 @@
img:=PPM.readPPMFile("lenaGrey.ppm"); // a grey scale image
median:=histogramMedian(histogram(img));
median.println();
bw:=PPM(img.w,img.h);
// stream bytes from orginal, convert to black/white, write to new image
// each pixel is 24 bit RGB
img.data.pump(bw.data.clear(),'wrap(c){ if(c>median) 0xff else 0 });
bw.write(File("foo.ppm","wb"));