Joined: Sun Oct 19, 2008 3:47 pm Posts: 281 Has thanked: 0 time Have thanks: 1 time
we r final yr students.currently we r doing our project in image processing(TAMIL HANDWRITTEN RECOGNITION).the first step is Digitization of an image.for that image should be converted into 2D array.help us with an effective java coding for this process,
AskBot
Question subject: Re: image processing in java
Posted: Thu Oct 23, 2008 1:07 am
Joined: Sun Oct 19, 2008 3:47 pm Posts: 281 Has thanked: 0 time Have thanks: 1 time
I was a student from less than a year, by chance my whole graduation project was in Java, and using the Java 2D API most of the time. I got u this code from my project, hope it helps, for any question, or for the Java files, email me at: mohajami1984 (at) yahoo
Good luck,
Code:
public static void image(){ try { File f=new File("e:\\asd\\21.bmp");
//read the image into Buffer BufferedImage imgb=ImageIO.read(f);
//get the image width + height int imageW=imgb.getWidth(); int imageH=imgb.getHeight();
//define ONE dimsneion arry to read the image into int imgArr[]=new int[imageW*imageH];
//read all the the pixels info into the array imgb.getRGB(0,0,imageW,imageH,imgArr,0,imageW);
//NOTE: each element in the array will present: (all in Hex values) //1- Transperancy of the color //2- Red color //3- Green color //4- Blue color // //example if the color in the image was Lime (between green and yellow) //its RGB is (186,255,0) //the result will look like: FFBAFF00 , where: //FF mean full opaque //BA is 186 //FF is 255 //00 is 0
//this loop will show each pixel correspondent Hex value String out=""; for (int i = 0; i < imgArr.length; i++) { if (i % imageW ==0) out+="\n"; out+=Integer.toHexString(imgArr[i]).toUpperCase() + " "; }
//the follwoing code fills the array in 2D array //convert to 2D array int img2D[][]=new int[imageW][imageH];
for (int x = 0; x < imageW; x++) { for (int y = 0; y < imageH; y++) { img2D[x][y]=imgArr[y*imageW+x]; } }
//printing the new array (should be same as the previous time) out=""; for (int y = 0; y < imageH; y++) { for (int x = 0; x < imageW; x++) { out+=Integer.toHexString(img2D[x][y]) + " "; } out+="\n"; }
Joined: Fri Apr 29, 2011 12:43 pm Posts: 1 Has thanked: 0 time Have thanks: 0 time
Hi i am interested in Image Processing and Previously developed applications with C # I think also have an error in code i tried this code it's true.
Code:
String filename = File.separator+"tmp"; JFileChooser fileChooser = new JFileChooser(new File(filename));
fileChooser.showOpenDialog(mainPanel);
File file = fileChooser.getSelectedFile(); try { BufferedImage imBuf = ImageIO.read(file); int imgW = imBuf.getWidth(); int imgH = imBuf.getHeight(); int imgAr[] = new int[imgW*imgH];
//Bufferede img nin 0-0 dan w - h ye kadar olan kısmın rgb degerlerini alıp // imgAr dizisine döndürür; imBuf.getRGB(0, 0, imgW, imgH, imgAr, 0, imgW); //NOTE: //Dizideki elemanların herbir Hex degerleri karsılıgı //1- Transparanlık //2- Red //3- Green //4- Blue
String out="Naber ibrahim ?"; out +=" \n"+Integer.toString(imgAr[381]); JOptionPane.showMessageDialog(null, out); //imgAr[] de tek boyutlu hali bulunuyor dizinin;