Lec 1,2
Lec 1,2
java
1
2 public class ReadImage {
3
4 public static void main(String[] args) {
5 int pixels[][]={
6 {0,0,0,75,75,75,128,128,128,128,128},
7 {0,75,75,75,128,128,128,128,255,255,255},
8 {75,75,75,200,200,200,255,255,255,200},
9 {128,128,128,200,200,255,255,200,200,200},
10 {128,128,128,255,255,200,200,200,75,75},
11 {175,175,175,255,255,255,75,75,75,100},
12 {175,175,100,100,100,255,255,75,75,100},
13 {75,75,75,35,35,35,0,0,0,35},
14 {35,35,35,0,0,0,35,35,35,75},
15 {35,35,35,0,0,0,35,35,35,75},
16 {75,75,75,100,100,100,200,200,200,200}
17 };// end image
18 Image m1 = new Image(1024,1024,256); // define object of class image and set
Resolution
19 m1.setMatrix(pixels, 10, 10); // read image and its coordinate
20 m1.changeValue(5, 2, 250); // change in gray value
21 m1.printMatrix(); // print pixels of matrix
22 System.out.println();
23 System.out.println(">> The Maximum value is : "+m1.getMaximum());
24 System.out.println(">> The Minimum value is : "+m1.getMinimum());
25 System.out.println(">> The Mean is : "+m1.getMean());
26 System.out.println(">> The Standard Division is : "+m1.getSTDivision());
27 System.out.println(">> The Resolution of Image is : "+m1.getResolution()/
(1024*1024*8)+" MB");
28 System.out.println(">> The Histogram : ");
29 System.out.println("----------------");
30 m1.printHistogram();
31
32
33 }// end main
34
35 }// end class
36
Page 1
Image.java
1 import java.lang.*;
2 public class Image {
3 private int rows ,cols;
4 private int pixels[] [];
5 int M,N,q;
6 private int hists[]= new int [256]; // Gray Level Array has 256 Values
7
8 public Image(int M, int N, int q){
9
10 if(M >0 && N >0 && q>0){
11 this.M=M;
12 this.N=N;
13 this.q=q;
14 }
15 else{
16 this.M=0;
17 this.N=0;
18 this.q=0;
19 }
20 }// end constructor
21
22 public void setMatrix(int pixels[][] ,int rows , int cols ){
23 if(rows>0 && cols>0){
24 this.rows=rows; // pass the rows_value to this.rows
25 this.cols=cols;// pass the cols_value to this.cols
26 this.pixels=pixels; // pass the pixels [][] to this.pixels
27 }// end condition
28 }// end set Matrix
29
30 public void changeValue(int rLoc , int cLoc, int q_Value){
31 if(rLoc>-1 && rLoc<rows&&cLoc>-1 && cLoc<cols ){//check correct range of index
32 if(q_Value>=0 && q_Value<=255){//check the correct value of quantization
33 int old_Value=pixels[rLoc][cLoc];
34 pixels[rLoc][cLoc]=q_Value;
35 System.out.printf(">> The Pixel [%d][%d] was changed from %d to
%d",rLoc,cLoc,old_Value,q_Value);
36 System.out.println();
37 }// end check the correct value of quantization
38 else{
39 System.out.println("!!! Enter Correct Value the range (0-255)");
40 }
41 }// end check correct range of index
42
43 else
44 System.out.println("!!! Check your index please");
45 }// end changeMatrixValues
46
47 public void printMatrix(){
48 System.out.println();
49 for (int i=0; i<rows;i++){
50 for(int j=0;j<cols;j++){
51 if(this.pixels[i][j]<9) // Check if Ones nums
52 System.out.print(" "); // margin Ones numbers
53 else if(this.pixels[i][j]<100)//Check if Tens nums
54 System.out.print(" "); // margin Tens numbers
55 else // Check if Hundreds nums
56 System.out.print(" "); // margin Hundreds numbers
57 System.out.print(this.pixels[i][j]);
58 }// end columns (n)
59 System.out.println();
60 }// end rows (M)
Page 1
Image.java
Page 2