@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 wr = img.getRaster() buf = new int[wr.getNumDataElements()] def color1 = 0xBBBF45 def red = (color1 >> 16) & 0xff def green = (color1 >> 8) & 0xff def blue = color1 & 0xff for(int ly=0;ly<wr.getHeight();ly++){ for(int lx=0;lx<wr.getWidth();lx++){ wr.getPixel(lx, ly, buf) def mono = (buf[0] * 77 + buf[1] * 151 + buf[2] * 28) >> 8; buf[0] = (int)(mono * red / 255) buf[1] = (int)(mono * green / 255) buf[2] = (int)(mono * blue / 255) wr.setPixel(lx, ly, buf) } } def bf = new BlockFilter() bf.setBlockSize(5) img = bf.filter(img, null) def df = new DiffuseFilter() df.setScale(3) img = df.filter(img, null) ImageIO.write(img, "png", new File("monotoneblock.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment