Created
March 14, 2017 11:13
-
-
Save kinow/5da61ff4af1bd7c515ceefb4aef2ced9 to your computer and use it in GitHub Desktop.
temp groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cp ~/.m2/repository/net/imagej/ij/1.51j/ij-1.51j.jar ~/.jenkins/war/WEB-INF/lib/ | |
import java.awt.Color | |
import java.awt.image.BufferedImage | |
import ij.ImagePlus | |
import ij.io.FileSaver; | |
import ij.process.ImageProcessor; | |
inputFile = "/home/kinow/Downloads/gallery/in.jpg" | |
outputFile = "/home/kinow/Downloads/gallery/out.jpg" | |
imgPlus = new ImagePlus("file://${inputFile}"); | |
imgProcessor = imgPlus.getProcessor(); | |
fs = new FileSaver(imgPlus); | |
bufferedImage = imgProcessor.getBufferedImage(); | |
for (int y = 0; y < bufferedImage.getHeight(); y++) { | |
for (int x = 0; x < bufferedImage.getWidth(); x++) { | |
color = new Color(bufferedImage.getRGB(x, y)); | |
grayLevel = (int) (color.getRed() + color.getGreen() + color.getBlue()) / 3; | |
r = (int) grayLevel; | |
g = (int) grayLevel; | |
b = (int) grayLevel; | |
rgb = (r << 16) | (g << 8) | b; | |
bufferedImage.setRGB(x, y, rgb); | |
} | |
} | |
grayImg = new ImagePlus("gray", bufferedImage); | |
fs = new FileSaver(grayImg); | |
fs.saveAsJpeg("${outputFile}"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment