@Grab(group='com.jhlabs', module='filters', version='2.0.235') import java.awt.* import java.awt.image.* import java.io.* import javax.imageio.* import com.jhlabs.composite.* import com.jhlabs.image.* // 影を強調した手書きの絵のように変換する def img = ImageIO.read(new File("sf2.jpg")) def tf = new ThresholdFilter(102) tf.setWhite(0xffffff) tf.setBlack(0x000000) img = tf.filter(img, null) def wr = img.getRaster() def buf = new int[wr.getNumDataElements()] for(int ly=1;ly<wr.getHeight();ly+=2){ for(int lx=0;lx<wr.getWidth();lx++){ wr.getPixel(lx, ly, buf) def ratio = (float)0.5f + Math.random()*0.2 buf[0] = Math.min(255, (int)(buf[0] * ratio)) buf[1] = Math.min(255, (int)(buf[1] * ratio)) buf[2] = Math.min(255, (int)(buf[2] * ratio)) wr.setPixel(lx, ly, buf) } } def nf = new NoiseFilter() nf.setMonochrome(true) img = nf.filter(img, null) def sf = new SmearFilter() sf.setShape(SmearFilter.LINES) sf.setDensity(0.8f) sf.setDistance(6) sf.setScatter(0.8f) sf.setAngle((float)Math.PI/4*3) img = sf.filter(img, null) ImageIO.write(img, "png", new File("thresholddrawing.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment