Results 1 to 2 of 2

Thread: binarization

  1. #1
    meth is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default binarization

    hi, i've been trying to do binarization on my system so that it will give black and white image. the system flow is: after i upload the original image, i have to go through every pixel in which that pixel contains density ranging from 0-255. and then i count the frequency of every density (yes, it will have an array of size 256) and compare it with the threshold value. if the frequency is less than the threshold value, set the density to 0 (black), else set to white (255). i've come until this far n i've been trying for the binarization for days but i cant make it. can anyone pls be kind enuf to assist me? thanks in advance!





    Java Code:
    public class Freq extends javax.swing.JFrame {
    .
    .
    .
    
     private void openbuttonActionPerformed(java.awt.event.ActionEvent evt) {                                           
            fileopen.addChoosableFileFilter(filter);
    
            int return_value = fileopen.showOpenDialog(this);
    
            if (return_value == JFileChooser.APPROVE_OPTION) {
                file_input = fileopen.getSelectedFile();
                System.out.println(file_input);
            }
            try {
                inputimage = ImageIO.read(file_input);
                inputimage = inputimage.getScaledInstance(256,256,Image.SCALE_SMOOTH);
                repaint();
            } catch(IOException e) {
                System.out.println("ERROR");
            }
    }                                          
    
    private void processActionPerformed(java.awt.event.ActionEvent evt) {                                        
            width = inputimage.getWidth(null);
            height = inputimage.getHeight(null);
    
           buff_red = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
            Graphics r = buff_red.getGraphics();
            r.drawImage(inputimage, 0, 0, null);
            r.dispose();
           
            process_red = new int[width*height];
            counter = 0;
            for(int i = 0; i < 256; i++) {
                for(int j = 0; j < 256; j++) {
                    int clr = buff_red.getRGB(j, i);
                    int red = (clr & 0x00ff0000) >> 16;
                    red = (0xFF<<24)|(red<<16)|(red<<8)|red;
                    process_input[counter] = clr;
                    process_red[counter] = red;
                    counter++;
        
    
    
    
                }
            }
            
            
            repaint();      
    }

  2. #2
    doWhile is online now Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    And what is the problem? What do you except and what do you get? A threshold value is never defined in your code, so how will you compare it to this value? Do you expect to average the RGB values for threshold comparison? Suggested reading: How To Ask Questions The Smart Way

Similar Threads

  1. error reported when binarization of gray image
    By Mazharul in forum Java 2D
    Replies: 1
    Last Post: 09-18-2008, 09:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •