-
Notifications
You must be signed in to change notification settings - Fork 1
/
ImageProcessor.java
64 lines (52 loc) · 1.92 KB
/
ImageProcessor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.io.File;
import java.io.IOException;
import java.awt.image.RenderedImage;
import javax.imageio.ImageIO;
import javax.media.jai.JAI;
public class ImageProcessor{
ProcessList process;
/**
*
* @param args The images to operate on
*/
public static void main(String args[]){
if(args.length < 1){
System.out.println("Need a file to convert to a binary image");
System.exit(1);
}
ImageProcessor process = new ImageProcessor();
for(int n = 0; n < args.length; n++){
try{
process.categorizeImage(args[n]);
}catch(IOException e){
System.err.println("Error reading " + args[n] + ": "
+ e.getMessage());
}
}
}
public ImageProcessor(){
//build up the image process
process = new ProcessList();
process.add(new MorphologicalCloseProcess());
process.add(new GrayConvertProcess());
process.add(new MonoscaleProcess());
SobelDetectionProcess sobel = new SobelDetectionProcess();
process.add(sobel);
}
public Category categorizeImage(String filename)
throws IOException{
RenderedImage inputImg = ImageIO.read(new File(filename));
HoughTransformer trans = new HoughTransformer(250, .70, 100.0);
RenderedImage outputImg = process.process(inputImg);
Category cat = trans.process(outputImg);
//if undefined, try processing again, without the Sobel operator
if(cat == Category.UNDEFINED){
ImageProcess sobel = process.get(process.size() - 1);
process.remove(process.size() - 1);
cat = trans.process(process.process(inputImg));
process.add(sobel);
}
System.out.println("Input file " + filename + ": " + cat);
return cat;
}
}