5
5
import javax .media .jai .JAI ;
6
6
7
7
public class ImageProcessor {
8
+
9
+ ProcessList process ;
8
10
9
11
/**
10
12
*
@@ -16,43 +18,47 @@ public static void main(String args[]){
16
18
System .exit (1 );
17
19
}
18
20
19
- //Build up the processor
20
- ProcessList processor = new ProcessList ();
21
- processor .add (new MorphologicalCloseProcess ());
22
- processor .add (new GrayConvertProcess ());
23
- processor .add (new MonoscaleProcess ());
24
- SobelDetectionProcess sobel = new SobelDetectionProcess ();
25
- processor .add (sobel );
26
-
27
- //the third parameter is a placeholder until I can try something
28
- //different
29
- HoughTransformer trans = new HoughTransformer (200 , .70 , 100.0 );
21
+ ImageProcessor process = new ImageProcessor ();
22
+
30
23
31
24
for (int n = 0 ; n < args .length ; n ++){
32
- String inputFilename = args [n ];
33
- String outputFilename = inputFilename .substring (0 , inputFilename .lastIndexOf ('.' )) + "PR.jpg" ;
34
- RenderedImage inputImg ;
35
-
36
25
try {
37
- inputImg = ImageIO . read ( new File ( inputFilename ) );
26
+ process . categorizeImage ( args [ n ] );
38
27
}catch (IOException e ){
39
- System .err .println ("Error reading " + outputFilename + ": "
28
+ System .err .println ("Error reading " + args [ n ] + ": "
40
29
+ e .getMessage ());
41
- continue ;
42
30
}
43
-
44
- RenderedImage outputImg = processor .process (inputImg );
45
- Category cat = trans .process (outputImg );
31
+ }
32
+ }
33
+
34
+ public ImageProcessor (){
35
+ //build up the image process
36
+ process = new ProcessList ();
37
+ process .add (new MorphologicalCloseProcess ());
38
+ process .add (new GrayConvertProcess ());
39
+ process .add (new MonoscaleProcess ());
40
+ SobelDetectionProcess sobel = new SobelDetectionProcess ();
41
+ process .add (sobel );
42
+ }
43
+
44
+ public Category categorizeImage (String filename )
45
+ throws IOException {
46
46
47
- //if undefined, try processing again, without the Sobel operator
48
- if (cat == Category .UNDEFINED ){
49
- processor .remove (sobel );
50
- outputImg = processor .process (inputImg );
51
- cat = trans .process (outputImg );
52
- processor .add (sobel );
53
- }
54
-
55
- System .out .println ("Input file " + inputFilename + ": " + cat );
47
+ RenderedImage inputImg = ImageIO .read (new File (filename ));
48
+
49
+ HoughTransformer trans = new HoughTransformer (250 , .70 , 100.0 );
50
+ RenderedImage outputImg = process .process (inputImg );
51
+ Category cat = trans .process (outputImg );
52
+
53
+ //if undefined, try processing again, without the Sobel operator
54
+ if (cat == Category .UNDEFINED ){
55
+ ImageProcess sobel = process .get (process .size () - 1 );
56
+ process .remove (process .size () - 1 );
57
+ cat = trans .process (process .process (inputImg ));
58
+ process .add (sobel );
56
59
}
60
+
61
+ System .out .println ("Input file " + filename + ": " + cat );
62
+ return cat ;
57
63
}
58
64
}
0 commit comments