Skip to content

Instantly share code, notes, and snippets.

@memish
Created October 23, 2017 20:44
Show Gist options
  • Save memish/edaf15d21c5c8b48f6015a25ebe01eda to your computer and use it in GitHub Desktop.
Save memish/edaf15d21c5c8b48f6015a25ebe01eda to your computer and use it in GitHub Desktop.
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.swing.ImageIcon;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class ExamineImage{
double[][] lumm;
int[][] aa ;
int[][] rr;
int[][] gg ;
int[][] bb ;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
public static String iImgName = "z";
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
public void rgb(String ffile) {
BufferedImage img=null;
File myFile = new File(ffile);
// File[] listOfFiles = myFolder.listFiles();
try{
if (myFile.isFile()) {
img = ImageIO.read(myFile);
int width=0;
int height=0;
int count=0;
double avg=0;
if(img!=null){
width = img.getWidth();
height = img.getHeight();
}
System.out.println("Width " + width + " " + height);
/* */
aa = new int[width][height];
rr = new int[width][height];
gg = new int[width][height];
bb = new int[width][height];
lumm = new double[width][height];
for(int x=0; x< width; x++){
for (int y=0;y< height;y++){
int pixelCol = img.getRGB(x, y);
int a = (pixelCol >>> 24) & 0xff;
int r = (pixelCol >>> 16) & 0xff;
int g = (pixelCol >>> 8) & 0xff;
int b = pixelCol & 0xff;
/* */
aa[x][y] = a;
rr[x][y] = r;
gg[x][y] = g;
bb[x][y] = b;
lumm[x][y]= (0.2126*r) + (0.7152*g) + (0.0722*b);
}}
// image(rr,gg,bb,lumm);
}
}catch(Exception e){
System.out.println("THERE WAS A PROBLEM " + e);
}
}//end of lumanance method
//this creates a new image
public void image(int[][] red, int[][] green, int[][] blue, double[][] lum)
{
//make some changes to the pixels
/*
for(int x=0; x< red.length-1; x++){
for (int y=0;y < red[0].length-1;y++){
//CODING GOES HERE
}}
*/
//make changes above
//create new image using new values
BufferedImage img = new BufferedImage(red.length, red[0].length, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x< red.length; x++){
for (int y = 0; y< red[0].length; y++){
int r = red[x][y];
int g = green[x][y];
int b = blue[x][y];
int col = (r << 16) | (g << 8) | b;
img.setRGB(x, y, col);
}}
File f = new File("inverted.jpg");
try{
ImageIO.write(img, "JPEG", f);
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
iImgName = "inverted.jpg";
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
} catch(Exception e){
}
}
}//end of class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment