Results 1 to 2 of 2

Thread: binarization

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

    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) {                                           
            int return_value = fileopen.showOpenDialog(this);
            if (return_value == JFileChooser.APPROVE_OPTION) {
                file_input = fileopen.getSelectedFile();
            try {
                inputimage =;
                inputimage = inputimage.getScaledInstance(256,256,Image.SCALE_SMOOTH);
            } catch(IOException e) {
    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);
            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;

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Rep Power


    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