@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 mf = new MedianFilter() img = mf.filter(img, null) def wr = img.getRaster() 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) buf[0] = Math.min(255, (int)(buf[0] * 1.7f)) buf[1] = Math.min(255, (int)(buf[1] * 1.7f)) buf[2] = Math.min(255, (int)(buf[2] * 1.7f)) wr.setPixel(lx, ly, buf) } } def sf = new SmearFilter() sf.setShape(SmearFilter.LINES) sf.setDensity(0.7f) sf.setDistance(7) sf.setScatter(0.8f) sf.setAngle((float)Math.PI/4) img = sf.filter(img, null) ImageIO.write(img, "png", new File("drawing.png"))元画像 出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment