Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static double x1,y1,x2,y2,x3,y3,x4,y4,X1,Y1,X2,Y2,X3,Y3,X4,Y4;
- public static void main(String[] args) {
- /*
- * read image
- */
- BufferedImage imgBuffer = null;
- try {
- imgBuffer = ImageIO.read(new File("C:\\Users\\mohar\\Desktop\\test\\3.jpg"));
- } catch (IOException ex) {
- Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
- }
- // int rgb_val = imgBuffer.getRGB(9, 9);
- // System.out.println(imgBuffer.getWidth());
- // System.out.println(imgBuffer.getHeight());
- // Color p = new Color(rgb_val);
- // System.out.println(p.getRed());
- // System.out.println(p.getGreen());
- // System.out.println(p.getBlue());
- /*
- * scale image
- */
- /*File output = new File("G:\\matlab practise\\output.jpg");
- try {
- ImageIO.write(sclae2(imgBuffer, 1000, 1280), "jpg", output);
- } catch (IOException ex) {
- Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
- }*/
- x1 = 319;
- y1 = 558;
- x2 = 1527;
- y2 = 534;
- x3 = 1675;
- y3 = 1939;
- x4 = 199;
- y4 = 1979;
- X1 = 0;
- Y1 = 0;
- X2 = 499;
- Y2 = 0;
- X3 = 499;
- Y3 = 499;
- X4 = 0;
- Y4 = 499;
- double M_a[][] = {
- {x1,y1,1,0,0,0,-x1*X1,-y1*X1},
- {x2,y2,1,0,0,0,-x2*X2,-y2*X2},
- {x3,y3,1,0,0,0,-x3*X3,-y3*X3},
- {x4,y4,1,0,0,0,-x4*X4,-y4*X4},
- {0,0,0,x1,y1,1,-x1*Y1,-y1*Y1},
- {0,0,0,x2,y2,1,-x2*Y2,-y2*Y2},
- {0,0,0,x3,y3,1,-x3*Y3,-y3*Y3},
- {0,0,0,x4,y4,1,-x4*Y4,-y4*Y4},
- };
- double M_b[][] = {
- {X1},
- {X2},
- {X3},
- {X4},
- {Y1},
- {Y2},
- {Y3},
- {Y4},
- };
- Matrix A = new Matrix(M_a);
- Matrix B = new Matrix(M_b);
- Matrix C = A.solve(B);
- double a = C.get(0, 0);
- double b = C.get(1, 0);
- double c = C.get(2, 0);
- double d = C.get(3, 0);
- double e = C.get(4, 0);
- double f = C.get(5, 0);
- double g = C.get(6, 0);
- double h = C.get(7, 0);
- int width = imgBuffer.getWidth();
- int height = imgBuffer.getHeight();
- BufferedImage output = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB);
- int max = -5000;
- int min = 5000;
- for (int i = 0; i < width; i++) {
- for (int j = 0; j < height; j++) {
- if(isInside(i, j)){
- int x = (int)(((a*i)+(b*j)+c)/((g*i)+(h*j)+1));
- int y = (int)(((d*i)+(e*j)+f)/((g*i)+(h*j)+1));
- if(y > max) max = y;
- if(y < min) min = y;
- int p = imgBuffer.getRGB(i, j);
- output.setRGB(x, y, p);
- }
- }
- }
- System.out.println("max: " + max);
- System.out.println("min: " + min);
- File output1 = new File("C:\\Users\\mohar\\Desktop\\test\\bal.jpg");
- try {
- ImageIO.write(output, "jpg", output1);
- } catch (IOException ex) {
- Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public static boolean isInside(int x, int y){
- double apd = Math.abs(0.5 * (x1*y+x*y4+x4*y1-x*y1-x4*y-x1*y4));
- double dpc = Math.abs(0.5 * (x4*y+x*y3+x3*y4-x*y4-x3*y-x4*y3));
- double cpb = Math.abs(0.5 * (x3*y+x*y2+x2*y3-x*y3-x2*y-x3*y2));
- double pba = Math.abs(0.5 * (x*y2+x2*y1+x1*y-x2*y-x1*y2-x*y1));
- double rec = Math.abs(0.5 * (x1*y2+x2*y3+x3*y4+x4*y1-x2*y1-x3*y2-x4*y3-x1*y4));
- if((apd + dpc + cpb + pba) > rec){
- return false;
- }else{
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement