Results 1 to 7 of 7
  1. #1
    TamTam is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default display histogram that count white pixels

    Hi ...I am a begginner in Java and i've beem working on a project for 2 weeks with NO SOLUTION!!!! ..my target is to display a histogram (its x-axis is the wedth of monochrome image and y-axis doesn't matter) that counts appearance of white color so that am able CROP ONLY WHITE REGIONS IN MY IMAGE...all the histograms i found and with some help i realized that there is no code to count white pixels...there is the histogram that give frequency on appearnce of every color from 0 to 255.....i have this function which works on the login of passing on every column in the image and check if it's white pixel ..Any Suggestion???

    Java Code:
    public ColumnHistogram(int[] hist) { 
                 this.hist = hist; 
           }

    Java Code:
     int[] hist = new int[image.getWidth()];
     
    java.awt.image.Raster rast = image.getData();
     
    int[] rgb = new int[rast.getNumBands()];
    for (int x = 0; x < image.getWidth(); x++) {
        for (int y = 0; y < image.getHeight(); y++) {
            rast.getPixel(x, y, rgb);
            if(rgb[0] == 255 && rgb[1] == 255 && rgb[2] == 255) {
                hist[x]++;
            }
        }
    }

    it is logic but not sure if it is correct!!!

  2. #2
    TamTam is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    or not histogram...any graph that shows number of white pixels in each column(of pixels) of an image!!

  3. #3
    TamTam is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    Sorry for always adding but i want to be as clear as possible...Where can I find code for this:Displays a two-dimensional graph of the intensities of pixels along a line within the image. The x-axis represents distance along the line and the y-axis is the pixel intensity.

  4. #4
    paul pasciak is offline Senior Member
    Join Date
    Jul 2008
    Posts
    125
    Rep Power
    0

    Default

    It appears to me that you are working
    on a very complex project for which
    one answer will not provide all the
    answers you need.

    There is a project I have used,
    that provides a 'testbed' to work on
    ideas like those you are trying.

    Briefly, Richard G. Baldwin has
    produced java code called "ImagMod02"

    Do a search using:

    "Baldwin ImagMod02"

    to find the code.

    You may find some of the code confusing,
    but still, it's quite easy to modify and toy
    with.

    This seems like the best answer to
    your needs.

  5. #5
    TamTam is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    Yes you are right ...i will check the search about ""Baldwin ImagMod02"" but in parallel i have a question to keep working on my plan..i got the function that counts white pixels here it is:

    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;

    public class Main

    { public Main() throws IOException
    {
    File file = new File("c:\\capture.bmp");
    BufferedImage orig = ImageIO.read(file);


    int w=orig.getWidth();
    int h=orig.getHeight();
    int[] n ;
    n=new int[w];
    for (int x = 0; x < w; x++) {

    int c=0;
    for (int y = 0; y < h; y++) {
    if(orig.getRGB(x,y)==-1){c++;}

    }
    n[x]=c;
    System.out.println(n[x]);
    }
    System.out.println("width of picture= "+w);
    }


    public static void main(String[] argv) throws IOException
    { Main app = new Main();}


    }
    ..

    but what if instead i want to count how many time do i jump from shite pixel to black one??in other words how many times do i have consecutive white pixel followed directly by black pixel??? i have this idea:
    for (int x = 0; x < w; x++) {
    int x1;
    x1=x+1;
    int c=0;
    for (int y = 0; y < h; y++) {
    int y1;
    int y1=y+1;
    if(orig.getRGB(x,y)==-1)&& if(orig.getRGB(x1,y1)==- -16777216){c++;}

    }
    n[x]=c;
    System.out.println(n[x]);
    }
    but it gave me an error concerning buffer ....Any Idea???

  6. #6
    paul pasciak is offline Senior Member
    Join Date
    Jul 2008
    Posts
    125
    Rep Power
    0

    Default Detecting a primitive edge in an image

    This response is a couple of days late.
    You have probably figured out some of
    this by now, but you might like the
    feedback.

    First, I think your reasoning in the
    design of your algorithm is good.
    I ran your Main program and it seems
    to meet your goal.

    Your white/black algorithm seems good.
    You will probably have to change your
    first for-loop to:

    for(int x=0; x<w-1; x++)

    You have probably figured out that the
    logic in your if statment should be:

    if((org.getRGB(x,y)==-1) && (org.getRGB(x1,y1)==-16777216))

  7. #7
    TamTam is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default

    Thanks for your reply !! Yes i found a solution..it is what u mentioned plus adding || for reversing x,x1 and y,y1..

Similar Threads

  1. BufferStrategy and white rows of pixels
    By TobyLobster in forum Java 2D
    Replies: 2
    Last Post: 12-29-2008, 01:49 PM
  2. Regarding the display of histogram
    By Mazharul in forum Java 2D
    Replies: 2
    Last Post: 08-27-2008, 03:09 AM
  3. Arrays and Histogram Help Needed
    By sebbybey in forum New To Java
    Replies: 3
    Last Post: 08-15-2008, 09:00 PM
  4. How to create a Histogram
    By Devilsfutbol17 in forum New To Java
    Replies: 4
    Last Post: 06-04-2008, 09:22 PM
  5. White Space Issue
    By sibythoma1984 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-22-2008, 12:05 PM

Posting Permissions

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