source: trunk/gli/src/org/greenstone/gatherer/feedback/SeparateGraphs.java@ 9078

Last change on this file since 9078 was 7315, checked in by kjdon, 20 years ago

Veronika's feedback code - still needs some work, but its disabled by default

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1package org.greenstone.gatherer.feedback;
2
3import java.io.*;
4import javax.imageio.*;
5import java.awt.*;
6import java.awt.image.*;
7import com.sun.image.codec.jpeg.*;
8import javax.swing.*;
9
10/**
11 * This class will separate a image file into 2 jpeg image files by taking
12 * all the point in that image file that has the color red and save all that
13 * points to another image file, while all the other point to another image
14 * file.
15 * @author Veronica Liesaputra
16 */
17public class SeparateGraphs
18{
19 /**
20 * This is the BufferedImage that we want to separate.
21 */
22 private BufferedImage bi;
23
24 /**
25 * This constructor will save the image inside the file with the specified
26 * filename to the BufferedImage.
27 */
28 public SeparateGraphs(String filename)
29 {
30 try
31 {
32 File f = new File(filename);
33 bi = ImageIO.read(f);
34 }
35 catch(IOException exp) {}
36 }
37
38 /**
39 * This method will separate bi into 2 image and save it to
40 * jpeg files with the specified filename.
41 * The 2 image separated will be, 1 image is the image of all the points in bi that
42 * have the color red and another image is the image of all other points in bi that
43 * do not have the color red.
44 * @param file1 this is the filename for the image of all other points that do not have color red.
45 * @param file2 this is the filename for the image of all points that have the color red.
46 */
47 public void separate(String file1,String file2)
48 {
49 BufferedImage bi1,bi2;
50
51 int width = bi.getWidth();
52 int height = bi.getHeight();
53
54 bi1 = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
55 bi2 = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
56
57 for (int y = 0 ; y < height ; y++)
58 {
59 for (int x = 0 ; x < width ; x++)
60 {
61 int rgb = bi.getRGB(x,y);
62 Color c = new Color(rgb,true);
63 if (c != Color.RED)
64 {
65 bi1.setRGB(x,y,rgb);
66 }
67 else
68 {
69 bi2.setRGB(x,y,rgb);
70 }
71 }
72 }
73
74 save(bi1,file1);
75 save(bi2,file2);
76 }
77
78 /**
79 * This method will save the BufferedImage into a jpeg file with the specified filenames.
80 * @param b is the BufferedImage to be saved.
81 * @param filename is the name of the jpeg files.
82 */
83 public void save(BufferedImage b,String filename)
84 {
85 try
86 {
87 File file = new File(filename);
88 FileOutputStream out = new FileOutputStream(file);
89
90 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
91 JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(b);
92 param.setQuality(1.0f, false);
93 encoder.setJPEGEncodeParam(param);
94 encoder.encode(b);
95
96 } catch (Exception ex) {}
97 }
98}
99
100
101
102
103
Note: See TracBrowser for help on using the repository browser.