Looking for the brighter red pixel of an image

Hi, I need to find the brighter red pixel of an image. I tried this code, but the value of each pixel seemed to be the same (zero).
public static void findBrighterRedPoint(Image i, ImageObserver o){
     int redMax = 0; //0 to 255
     int xMax = 0;
     int yMax = 0;
     PixelGrabber pg = new PixelGrabber(i,0,0,i.getWidth(o),i.getHeight(o),true);
     ColorModel cm = pg.getColorModel();
     for(int a=0;a<pg.getHeight();a++){
          for(int c=0;c<pg.getWidth();c++){
               if(cm.getRed(((a-1)*pg.getWidth()+c)) > redMax){
                    redMax = cm.getRed(((a-1)*pg.getWidth()+c));
                    xMax=c;
                    yMax=a;
               if(f==(pg.getHeight()-1) && c==(pg.getWidth()-1)){
               System.out.println("Red bound max value: "+cm.getRed(((a-1)*pg.getWidth()+c))+" Arrow: "+a+" Collumn: "+c);
}//method endThanks for some help...
Edited by: juanma268 on Jul 25, 2008 5:45 PM

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
public class LookingForRed extends MouseMotionAdapter {
    JLabel red, green, blue;
    BufferedImage image;
    public void mouseMoved(MouseEvent e) {
        Point p = e.getPoint();
        int rgb = image.getRGB(p.x, p.y);
        red.setText(String.valueOf(  (rgb >> 16)&0xff));
        green.setText(String.valueOf((rgb >>  8)&0xff));
        blue.setText(String.valueOf( (rgb >>  0)&0xff));
    public static void findBrighterRedPoint(Image i, ImageObserver o){
        int redMax = 0; //0 to 255
        int xMax = 0;
        int yMax = 0;
        int w = i.getWidth(o);
        int h = i.getHeight(o);
        int[] pixels = new int[w*h];
        PixelGrabber pg = new PixelGrabber(i,0,0,w,h,pixels,0,w);
        try {
            pg.grabPixels();
        } catch(InterruptedException e) {
            System.out.println("interrupt");
        ColorModel cm = pg.getColorModel();
        for(int a=0;a<pg.getHeight();a++){
            for(int c=0;c<pg.getWidth();c++){
                int index = a*pg.getWidth()+c;
                int pixel = pixels[index];
                if(cm.getRed(pixel) > redMax){
                    redMax = cm.getRed(pixel);
                    xMax=c;
                    yMax=a;
                if(a==(pg.getHeight()-1) && c==(pg.getWidth()-1)){
                    System.out.println("Red bound max value: "+redMax+
                               " Arrow: "+yMax+" Collumn: "+xMax);
    private void showGUI(BufferedImage image) {
        this.image = image;
        ImageIcon icon = new ImageIcon(image);
        JLabel label = new JLabel(icon, JLabel.CENTER);
        label.addMouseMotionListener(this);
        JPanel panel = new JPanel(new GridBagLayout());
        panel.add(label, new GridBagConstraints());
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(panel);
        f.add(getLabelPanel(), "Last");
        f.setSize(300,300);
        f.setLocation(200,200);
        f.setVisible(true);
        findBrighterRedPoint(image, label);
    private JPanel getLabelPanel() {
        red = new JLabel();
        green = new JLabel();
        blue = new JLabel();
        Dimension d = new Dimension(45, 25);
        JPanel panel = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(2,2,2,2);
        gbc.weightx = 1.0;
        addComponents("r =", red,   panel, gbc, d);
        addComponents("g =", green, panel, gbc, d);
        addComponents("b =", blue,  panel, gbc, d);
        return panel;
    private void addComponents(String s, JLabel jl, Container c,
                               GridBagConstraints gbc, Dimension d) {
        gbc.anchor = GridBagConstraints.EAST;
        c.add(new JLabel(s), gbc);
        jl.setPreferredSize(d);
        gbc.anchor = GridBagConstraints.WEST;
        c.add(jl, gbc);
    public static void main(String[] args) {
        LookingForRed test = new LookingForRed();
        BufferedImage image = test.makeImage();
        test.showGUI(image);
    private BufferedImage makeImage() {
        int w = 200, h = 200;
        int type = BufferedImage.TYPE_INT_RGB;
        BufferedImage image = new BufferedImage(w, h, type);
        int[] data = new int[w*h];
        int x = 3*w/4;
        int y = 3*h/4;
        System.out.println("Max red value should appear at " +
                           "x = " + x + "  y = " + y);
        int a = 255;
        for(int j = 0; j < h; j++) {
            int b = j*255/(h-1);
            for(int k = 0; k < w; k++) {
                int r = (j == y && k == x) ? 255 : 127;
                int g = k*255/(w-1);
                data[j*w + k] = ((a & 0xff) << 24) |
                                ((r & 0xff) << 16) |
                                ((g & 0xff) <<  8) |
                                ((b & 0xff) <<  0);
        image.setRGB(0,0,w,h,data,0,w);
        return image;
}

Similar Messages

  • Looking for the most easy way to position images on a page!?

    Hi, I'm looking for the most easy way for exact position a lot of PNG images on a web page. Input appreciated!
    Thanks!

    Basic 1-col layout with 3 evenly spaced boxes:
    http://alt-web.com/TEMPLATES/Basic-1-col-fixed.html
    CSS Floats and Margins tutorial -
    http://alt-web.com/DEMOS/3-CSS-boxes.shtml
    Float left & float right  images with wrapping  text
    http://alt-web.com/DEMOS/CSS2-Captions-on-floated-images.shtml
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    www.alt-web.com/
    www.twitter.com/altweb
    www.alt-web.blogspot.com

  • When i try to use my ipod it looks like the brightness was turned wayyyyy down. Like more than normal. I cant see anything. How do i fix it?

    When i try to use my ipod it looks like the brightness was turned wayyyyy down. Like more than normal. I cant see anything. How do i fix it?

    Try:
    - Reset the iOS device. Nothing will be lost       
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                                
    iOS: How to back up                                                                                     
    - Restore to factory settings/new iOS device.             
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
      Apple Retail Store - Genius Bar

  • Hi - I am looking for the Adobe Illustrator 2014 1.2 (or .0.2) bugfix update for Mac - and it is not visible in the Adobe Creative Cloud Packager (Mac version). The only update visible is Illustrator CC 2014.1  - which is what introduced the bugs.

    Hi - I am looking for the Adobe Illustrator 2014 1.2 (or .0.2) bugfix update for Mac - and it is not visible in the Adobe Creative Cloud Packager (Mac version). The only update visible is Illustrator CC 2014.1  - which is what introduced the bugs.
    The only thing that I can think of that might be causing the issues that I have a Mac Mini on Mavericks.
    Dave

    Hi
    I have discovered that my question above is a non-question. A user triggered by looking at the below article about Illustrator 2014 cc 17.0.2
    http://helpx.adobe.com/illustrator/release-note/illustrator-17-0-2-release-notes.html 
    He had recently upgraded from wht we now know is 18.0 to 18.1 which is the latest version. He read the above artic
    le and supposed that it was a bug fix release for his version - because the v17 ov18 number is not often displayed. It is usually just 2014 CC.
    I have asked him to post a bug report about Adobe Illustrator CC 2014.1
    Dave

  • I cannot add a Wi-Fi guest network. Gone to Utilities Airport Utilities and all get is an image/browser of my Airport Extreme. Looking for the browser which has the title Wireless but cannot find anywhere. I need help?

    I cannot add a Wi-Fi guest network. Gone to Utilities>Airport Utilities and all I get is an image/browser of my Airport Extreme. Looking for the browser window which has the title Wireless but cannot find anywhere. What am I doing wrong?

    Open AirPort Utility. The first screen looks something like this:
    Click on the AirPort Extreme and another screen will appear. Click Edit, then the window with the Wireless tab will appear.
    If you do not see these screens, you will need to start over and configure your AirPort again.

  • Problem with my program looking for the settings file in the wrong folder

    I have been writing a simple FTP file uploader, what I want to do is be able to select the files I want to upload in windows explorer and then right click and click the menu item and it launches the program and passes the files paths that I have selected to it.
    So I use this in the windows registry "C:\Program Files\Java\jre1.6.0_03\bin\java.exe -jar D:\BenFTP\BenFTP.jar %1"
    It launches fine and has no problem finding the files I want to upload. The problem is that it tries to look for the settings file in the same folder that the file I am try to upload is in. Which it's not suppose to do since the settings file is in the same folder that the .jar is in.
    Edited by: ColNewman on Feb 5, 2008 6:55 PM

    So, you're looking for your settings file in your current working directory. There's no way to set the CWD in your registry entry (is there?) so that isn't a practical thing to do. Presumably you're using a File object or a FileReader or something? Can't do that.
    One alternative is to look for the settings file in the classpath. You can get a URL to a file in the classpath like this:URL settings = this.getClass().getResource("/settings.xml");Or you can get an InputStream to read the file by using the getResourceAsStream method. You would have to make sure that your executable jar file contained a Class-Path entry that specified the right directory, because the directory the jar is contained in isn't automatically in an executable jar's classpath.
    Another alternative is to ask the user where the settings file is supposed to be, and put an entry in the Preferences (java.util.prefs) to remember that location.

  • When I try to reset my iPad mini it keeps asking for  a passcode! have tried restoring, connecting to iTunes and looked for the 'set up as new iPad' notification, but nothing is working? can anyone help please?

    I know my passcode is correct but when I try to reset my iPad mini it keeps asking for  a passcode! have tried restoring, connecting to iTunes and looked for the 'set up as new iPad' notification, but nothing is working? can anyone help please?

    If the iPad was running iOS 7,  iCloud: Find My iPhone Activation Lock in iOS 7
    http://support.apple.com/kb/HT5818
    How can I unlock my iPad if I forgot the passcode?
    http://www.everymac.com/systems/apple/ipad/ipad-troubleshooting-repair-faq/ipad- how-to-unlock-open-forgot-code-passcode-password-login.html
    iOS: Device disabled after entering wrong passcode
    http://support.apple.com/kb/ht1212
    How can I unlock my iPad if I forgot the passcode?
    http://tinyurl.com/7ndy8tb
    How to Reset a Forgotten Password for an iOS Device
    http://www.wikihow.com/Reset-a-Forgotten-Password-for-an-iOS-Device
    Using iPhone/iPad Recovery Mode
    http://ipod.about.com/od/iphonetroubleshooting/a/Iphone-Recovery-Mode.htm
    Saw this solution on another post about an iPad in a school environment. Might work on your iPad so you won't lose everything.
    ~~~~~~~~~~~~~
    ‘iPad is disabled’ fix without resetting using iTunes
    Today I met my match with an iPad that had a passcode entered too many times, resulting in it displaying the message ‘iPad is disabled – Connect to iTunes’. This was a student iPad and since they use Notability for most of their work there was a chance that her files were not all backed up to the cloud. I really wanted to just re-activate the iPad instead of totally resetting it back to our default image.
    I reached out to my PLN on Twitter and had some help from a few people through retweets and a couple of clarification tweets. I love that so many are willing to help out so quickly. Through this I also learned that I look like Lt. Riker from Star Trek (thanks @FillineMachine).
    Through some trial and error (and a little sheer luck), I was able to reactivate the iPad without loosing any data. Note, this will only work on the computer it last synced with. Here’s how:
    1. Configurator is useless in reactivating a locked iPad. You will only be able to completely reformat the iPad using Configurator. If that’s ok with you, go for it – otherwise don’t waste your time trying to figure it out.
    2. Open iTunes with the iPad disconnected.
    3. Connect the iPad to the computer and wait for it to show up in the devices section in iTunes.
    4. Click on the iPad name when it appears and you will be given the option to restore a backup or setup as a new iPad (since it is locked).
    5. Click ‘Setup as new iPad’ and then click restore.
    6. The iPad will start backing up before it does the full restore and sync. CANCEL THE BACKUP IMMEDIATELY. You do this by clicking the small x in the status window in iTunes.
    7. When the backup cancels, it immediately starts syncing – cancel this as well using the same small x in the iTunes status window.
    8. The first stage in the restore process unlocks the iPad, you are basically just cancelling out the restore process as soon as it reactivates the iPad.
    If done correctly, you will experience no data loss and the result will be a reactivated iPad. I have now tried this with about 5 iPads that were locked identically by students and each time it worked like a charm.
    ~~~~~~~~~~~~~
    Try it and good luck. You have nothing more to lose if it doesn't work for you.
     Cheers, Tom

  • How to look for the Table Name

    Hi Friends,
    Sometimes we need to download the table for the desired information if the same is not available from a particular report. How to look for the table name? Is there a report or a particular feild, where we can find the name of the particular table?
    Thanks for the assistance.
    Regards

    Hi Friend,
    If you want to see the structures then go to SE11. Sometimes it happens that you cannot find the table names but only fields. In such case, if you want to find the Table names which is not available, then go to SE90.
    Abap Dictionary > Fields > Table Fields.
    Now Enter the Field name in Right Hand Side of the screen then Execute. You will see the all tables by which that Fields are used.
    Regards,
    Jigar

  • Where to look for the computed stats collected using gather_table_stats

    I have used analyze command before but new to gather_table_stats.
    I have executed gather_table_stats procedure as given below. Now where to look for the statistics estimated and also what are the important parameters I need to look in the stats ? Any major difference between analyze & gather_table_stats ?
    SQL> exec dbms_stats.gather_table_stats(ownname => 'TPDBS01A', tabname => 'x_TPD_STG_TL_SF_LEGAL_OWN
    ER' , estimate_percent => 50, method_opt => 'for all indexed columns size auto');
    PL/SQL procedure successfully completed.

    The command "analyze table" is deprecated for gathering optimizer statistics. But it is still the only command to get for instance the chained rows. This command is no longer maintained for new features, so if you use this command to collect statistics, it might not collect all needed numbers for the optimizer so the plan could be wrong.
    The package dbms_stats is collecting all the figures that the optimizer needs to genererate an optimal access plan. All new database features are incorporated only here.
    The statistics numbers can be found in the normal tables like USER|ALL|DBA_TABLES, ...TAB_COLUMNS, ...INDEXES, ...IND_COLUMNS etc. There you can find for instance number of rows in table, clustering factor for indexes and more numbers like this. They are not really needed for us human beings, they are used by the optimizer to generate the access plan.

  • HT1349 hi guys i have 2 ? 1 my daughters iphone is trying to update on my mac cant get it off help please ,,, 2 i have an old apple id and when i try to up date it keeps looking for the password how do i delete this old apple id help

    hi guys i have 2 ? 1 my daughters iphone is trying to update on my mac cant get it off help please ,,, 2 i have an old apple id and when i try to up date it keeps looking for the password how do i delete this old apple id help

    Hi.
    I had a similar problem myself. This is what helped me.
    I went to the App store app, scrolled to the bottom, logged out of the account, re logged in with my Apple ID.  Then went back to app updates. Once I put in my ID password all was fine.

  • When my husband and I try to share our libraries and import from each others libraries, we get as far as seeing the library on the screen. The next step is to look for the 'Show' menu at the bottom of the screen, but neither of us has any such thing. ?

    When my husband and I try to import from each other's libraries, using Home Sharing, we are intructed to look for the "Show" menu at the bottom of the screen. Neither of us has anything like this on our screens. How and where do we locate it? We both have the latest itunes running.

    Hey fantail163,
    If you are not seeing the button to show menu, try out the troubleshooting steps for Home Sharing.
    Troubleshooting Home Sharing
    http://support.apple.com/kb/ts2972
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

  • On my iPod touch it says on the settings I have wifi but when I look for the 3 bars there is no wifi please help

    On my iPod touch it says on the settings i am connected to my home wifi but when I look for the 3. Bars beside the time they are not there this therefore stops me from using internet please help

    Does the iOS device connect to other networks?
    Does the iOS device see the network?
    Any error messages?
    Do other devices now connect?
    Did the iOS device connect before?
    Try the following to rule out a software problem:                 
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears. already suggested
    - Power off and then back on the router
    - Reset network settings: Settings>General>Reset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - Wi-Fi: Unable to connect to an 802.11n Wi-Fi network
    - iOS: Recommended settings for Wi-Fi routers and access points
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    If still problem make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar

  • TS4062 I've done all of these recommended steps.  My problem is that I have a new laptop that I am trying to sync my iPhone (and iPad for that matter) via Wi-Fi but both devices are looking for the old laptop to sync.  Any other suggestions?

    I've done all of these recommended steps.  My problem is that I have a new laptop that I am trying to sync my iPhone (and iPad for that matter) via Wi-Fi but both devices are looking for the old laptop to sync.  My iTunes is version 11.0..3.42, iPhone is 6.1.4, and iPad 6.1.3.  Any suggestions?

    All I had to do was complain.  I synced my iPhone to the Windows machine, checked the other account at iTunes prompting (where no apps had shown up previously), reconnected the iPad, and 140 apps downloaded including the App Store.  I have no idea why.

  • TS2776 I cannot get my IPhone to recognize my new computer; it's still looking for the old one.

    My IPhone won't sync with a new windows 8 computer.  It's still looking for the old one.  How in the he11 do you change the name of the PC the IPhone looks for?

    This user tip should be useful
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive

  • Can I force the bootcamp wizard to skip looking for the bootcamp drivers?  I have already downloaded the latest drivers and loaded them on a FAT usb drive.  All I want is for bootcamp to create the partition and allow me to install windows 8 pro

    Hi Everyone,
    Can I force the bootcamp wizard to skip looking for the bootcamp drivers?  I have already downloaded the latest drivers and loaded them on a FAT usb drive.  All I want is for bootcamp to create the partition and allow me to install windows 8 pro.
    The bootcamp drivers have been downloaded from apple's website.  Filename:  BootCamp5.0.5033
    I have a iMac 27" late 2013 model.
    NOTE:  I have downloaded the drivers manually from apples support site as the bootcamp wizard fails third of the way through the download.
    Appreciate any assistance.
    Regards,
    asdutoit

    There is a missing point in this thread, and it is that the Boot Camp drivers for the Late 2013 iMac can only be downloaded from Boot Camp Assistant. The Boot Camp drivers available in the Apple site are not compatible with that iMac.
    Delete the Boot Camp drivers from the USB drive, open Boot Camp Assistant and try to download the Boot Camp drivers again. If you get a message telling you that they could not be downloaded, I would try reinstalling OS X through OS X Recovery, by holding down Command and R keys while your Mac is starting up

Maybe you are looking for

  • Data not available in report S_ALR_87013604

    Hi All, For some company codes the data is not executed for the report S_ALR_87013604. We have three controlling area and assigned with compnay codes. only a few company code are excuting data. Is this a chance of inactive profitanalysis for some com

  • What's wrong with my computer network?

    Hello, recently Google Chrome has been displaying "Error 7 (net::ERR_TIMED_OUT)" on all pages i try to access. For a while, i thought it was a Chrome specific problem, so i did a lot of research on how i thought i could fix it.. i did many things, fr

  • How to send a SmartForm output as Email to external id?

    I want the Smartform output to email to extrenal email-id. I don't want the Smartform output as any kind of attachment, but the Smartform output needs to be shown on the main email body. Can anyone pls. help me out?

  • No Boot! CRASH?? Chime but nothing more

    Powerbook G4 17" 1.67ghz, 1G RAM I had to cold shutdown and when I restarted I heard the Chime like normal and the screen lit up with the off white like normal but nothing happened after that...it was stuck there. I listened and could hear clicking a

  • Video entro to dvd menu

    I love dvdsp and am a noob. i was wanting to creat an entro to a menu that where there is no blip of time between the intro video and the menu what is the best way to do that?   Mac OS X (10.4.5)