Image Erosion using a kernel

Hello all.
I am trying to change a black and white image. I want to perform erosion to increase gaps, etc. Does anyone know how I can erode a bufferedimage and get the result as a bufferedimage. I understand that I will have to use a kernel but I don't know how to implement this.
Please help if you can.

Ok so I am still playing around with this :-)
A very useful program to have when performing this kind of image manipulation is ZoomIn, which you can download for free from:
http://users.csc.calpoly.edu/~bfriesen/software/zoomin.shtml
Find below a simple manual implementation of a cross-like erosion kernel. Also notice the high number of operations involved (and I really don't know the cost of all these getRGB/setRGB calls). Working on a binary image (boolean array) instead of these BufferedImages should speed up things quite a lot.
import java.awt.BorderLayout;
import java.awt.image.BufferedImage;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Erosion {
    public static void main(String[] args) throws Exception {
        BufferedImage src = ImageIO.read(new URL(
                "http://homepages.inf.ed.ac.uk/rbf/HIPR2/thumbs/mon1thr1.GIF"));
        int w = src.getWidth();
        int h = src.getHeight();
        BufferedImage dest = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        final int BLACK = 0xFF000000;
        final int WHITE = 0xFFFFFFFF;
        for (int x = 1; x < w - 1; x++) {
            for (int y = 1; y < h - 1; y++) {
                // System.out.println(Integer.toHexString(src.getRGB(x, y)));
                // a cross-like kernel (left, right, top, bottom)
                if (src.getRGB(x - 1, y) != WHITE //
                        || src.getRGB(x + 1, y) != WHITE //
                        || src.getRGB(x, y - 1) != WHITE //
                        || src.getRGB(x, y + 1) != WHITE//
                    // if one neighbor pixel is black, make this one black too
                    dest.setRGB(x, y, BLACK);
                } else {
                    dest.setRGB(x, y, WHITE);
        JFrame f = new JFrame("Erosion");
        f.getContentPane().add(new JLabel(new ImageIcon(src)), BorderLayout.CENTER);
        f.getContentPane().add(new JLabel(new ImageIcon(dest)), BorderLayout.EAST);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
}

Similar Messages

  • Can I boot up a Tiger Disk IMage HDD using my Macbook Pro (with Leopard)

    Before my Ibook G4 crashed (tiger 10.4) I made a disk image using super duper. I purchased a Macbook Pro (leopard) and when I tried booting the disk Image I had made using superduper on a smart disk firewire drive, it would not recognize it.
    I held the option key when booting but only the Mac drive on the Macbook pro showed up. Is that a bug/flaw with leopard that you can't even boot an external HD disk image made using Tiger?
    I know the disk image is good because it boots on my G5 which has tiger installed.
    Thanks for a reply..
    Skip

    Allan Eckert and BCC99,
    Thanks for the responses. I REALLY appreciate it becuase I usually spend a lot of time spinning my wheels trying to make something work that doesn't.
    The reason I wanted to boot it was that my old IBOOK crashed and I wanted to boot up the old "clone" (not disk image - my poor choice of words) so that I could view some of my older emails that contained information that I wanted to view. I know I could do it on my G5 but I wasn't home and wanted to try my new Macbook.....
    Thanks again...
    Skip

  • I tried transferring my iphoto library from my old macbook onto my new macbook pro (via external hard drive), but when i open the new iphoto, it seems to have transferred ALL images ever used on my old macbook. so i tried to just del

    i tried transferring my iphoto library from my old macbook onto my new macbook pro (via external hard drive), but when i open the new iphoto, it seems to have transferred ALL images ever used on my old macbook. so i tried to just delete all those images so i could try a different approach to transferring, but the new iphoto won't let me do anything and every time i try to delete anything it crashes (since the image amount is so high).  please help!!
    MacBook Pro, OS X Mountain Lion (10.8.2), iphoto '11, version 9.4.2

    To move an iPhoto Library to a new machine:
    Link the two Macs together: there are several ways to do this: Wireless Network,Firewire Target Disk Mode, Ethernet, or even just copy the Library to an external HD and then on to the new machine...
    But however you do choose to link the two machines...
    Simply copy the iPhoto Library from the Pictures Folder on the old Machine to the Pictures Folder on the new Machine.
    Then launch iPhoto. That's it.
    This moves photos, events, albums, books, keywords, slideshows and everything else.

  • I tried transferring my iphoto library from my old macbook onto my new macbook pro, but when i open the new iphoto, it seems to have transferred ALL images ever used on my old macbook.  now iphoto won't let me do anything to fix!!

    i tried transferring my iphoto library from my old macbook onto my new macbook pro (via external hard drive), but when i open the new iphoto, it seems to have transferred ALL images ever used on my old macbook. so i tried to just delete all those images so i could try a different approach to transferring, but the new iphoto won't let me do anything and every time i try to delete anything it crashes (since the image amount is so high).  please help!!

    See http://support.apple.com/kb/HT1229?viewlocale=en_US - I doubt that it will solve your problem, though. You may want to post on the iPhoto forum - that's where all of the iPhoto experts hang out.
    Good luck,
    Clinton

  • Uploading image file using tcode se78  occuring some   Error

    Hai Gurus
          I am uploading image file using tcode se78 but while Uploading it giving some error i cant resolve the problem so any one help me plz
    Error    "Graphic LOGO could not be saved (2LOGO)"
    Regards
    Selvendran

    Hai
    Thanks
    I had done in all method but i can't save it 
    error is coming ..so plz help me to upload the image
    Error "Graphic LOGO could not be saved (2LOGO)"
    Regards
    Selvendran

  • How stop PS6 from removing the DPI value from an image when using "save for the web"?

    How stop PS6 from removing the DPI-value from an image when using "save for the web"?
    Example:
    - Open a tif image, that contains a dpi value (resolution).
    - Use the splice tool in PS6.
    - Export the slices with "Save for web", as gif-files.
    Then the dpi value is removed, the gif files has no dpi value (it's empty).
    How can we stop PS6 from removing the dpi value when using "save for web"?
    OR:
    When using the slice tool, how can we save the sliced pieces without PS removing the dpi value?

    you can make your art go a little bit over the bounds. or you can make sure your artboart and art edges align to pixels

  • What's the best way to save an 8.5 x 11 image for use as a page background in a PDF?

    What's the best way to save an 8.5 x 11 image for use as a page background in a PDF? My goal is to have a relatively small final .pdf file size that includes numerous pages with full 8.5 x 11 images as backgrounds in the document. If I save at 8.5 x 11 and 72dpi (example), the image is not 8.5 x 11, and the quality is not good enough. I need help with size, dpi, and file format to save as before I place it in InDesign and then save as a .pdf.
    Thanks,
    Jim

    Do exactly what I said then.  Create the InDesign document of the required dimension, and chose whether it will be high quality print, or Interactive PDF.  It really doesn't mater what format you bring the image into that document.  It can be JPG, PNG, but I usually use native Photoshop PSD.  The image does have to be of high enough resolution, but it can be many times bigger than iis required for the final export.  (InDesign does not import the image, but rather references it on your hard drive.)
    When you have placed your text and finished your page, then export it to PDF, but go through the tabs chosing suitable settings.  If the image needs to be downsized, InDesign will do that at this stage while building the PDF.
    If you can tell us how this presentation will be made (Projector, overhead projector, printed page etc. or just emailed to the end users) we can help you more with the final output settings. 

  • Copying member("aTextMemb").image into a rect in an image that uses alpha

    Hi all. I'm currently developping a strategy game with Director, and one of the things I've run into is that i want to update the number of units I have in a panel (on initial game setup) via 1) updating a text member that holds the number of units left to setup and copyPixeling the image onto the panel. This I've acheived except that since my text member image doesnt have alpha originally and the panel is semitransparent, a white (no matter the bckgrnd color I set for the text member) bounding box appears in the final result. I guess the way to go is duplicating the text member image and make it a 1 bit mask image then using the apropiate imaging lingo command (dont remember if it's copyPixels or another at this point). Imaging lingo is very interesting for me since normally I built all my aplications using the score directly (15 years exp with Director). This is my first game where I mostly rely on parent scripting and in some situations imaging lingo.
    This is currently the handler that does the job. It: 1) stores the image of the text member "panelCount" 2) defines the destinatiion rectangle where it will be copied in the panel bitmap and 3) copies it (but as I said the correct alpha is missing).
    on updateUnitsDisplay me
      member("panelCount").text= string(pPanelUnitCount)
      -- we retrieve the image of the text member that stores how many units left in the panel
      _textImage= member("panelCount").image 
      bottomMargin= 20 -- distance from the bottom of the panel that we want the text to be
      _left= (sprite(me.spriteNum).width- _textImage.width)/2
      _top= sprite(me.spriteNum).height- bottomMargin- (_textImage.height/2)
      _right= _left+ _textImage.width
      _bottom= _top+ _textImage.height
      destRect= rect(_left, _top, _right, _bottom)
      pPanelMember.image.copyPixels(_textImage, destRect, _textImage.rect) 
    end updateUnitsDisplay
    Your proposals and thoughts are welcome (specially good ones )
    EDIT: I've said above that my textImage wouldnt have alpha originally. Well, i think that was wrong according to what I've found in he scripting dictionary under the image() section "When you create a new image object, the background color defaults to white (color(255,255,255)), and the alpha channel is completely opaque (color(0,0,0))."
    On the other hand, the paramList in the copyPixels command should do it I think (a matte can be defined, also and ink mode for the copied pixels can be used although my first experiments have not worked yet).

    I think I got it. The paramList in the copyPixels command has been enough to get rid of the white box around the text (using #ink: 36 which is bckgrnd transparent in it), the problem was that I was using the same white for foreground and background colors in the text member (been some time not using director and misplaced the false white I used to use in these cases in the color selector). Bottom line, dont use exact same color values for back and fore colors of the text member. I've observed also that using the alpha of the image (useAlpha= true) makes it well antialiased while not using the alpha does produces a bad image of the text (btw, the font of the text is an inserted text media element of course). I keep investigating

  • How to upload a image file using JSP

    hello to all.
    i am in the learning stage please help me to upload a image file
    using jsp. give the explanation to the code also if possible.
    thanks in advance
    sincerely
    Chezhian

    You may find the following articles useful for the JSP/Servlet part:
    Uploading files: http://balusc.blogspot.com/2007/11/multipartfilter.html
    Downloading files: http://balusc.blogspot.com/2007/07/fileservlet.html

  • Can't select an image to use for a signature in Reader XI

    Using Adobe Reader XI, I can't select an image to use as a signature.  I have an image saved as a JPEG, but using an image is never an option.  I only see the option to use a certificate.
    Help!

    A signature in a PDF is a digital signature. It consists of metadate, and not an image or physical signature.

  • I want to make gImage Class extends Image and use Graphics2D

    Sorry, my english short...
    I want to make gImage Class extends Image and use Graphics2D
    I trying to do...
    make class gImage..
    extends Image class. (Inheritance)
    but Image class is abstract class..
    And I want to use gImage class same as Image class.
    I can't use constructor... because by Abstract calss...
    How do i?
    Help me.. plz...
    And I want to use Graphics2D at Applet Game, But not use Java JDK Plug-in...
    No Way?

    You need to use BufferedImage with 2D or RenderedImage with JAI.
    BufferedImage effectivley extends an Image so you can
    draw it to screen in paintCOmponent.
    I use an Extended JPanel to draw an image in a Panel with this.
    MArk

  • How can I see how often and where an image is used in the site?

    Just realized the post appeared twice as at first sending I
    got an error page (contains no data...).
    So, please do all answer to the other post, so that all
    replies get collected at one post only.
    Hello,
    please excuse my maybe dumb question but converting from
    GoLive I am still trying to find several practical effective
    workflow features in DW ...
    1. where in the sitewindow/assets or files panel can I see an
    indication at each image if and how often it is used in a site?
    2. and where can I see/check on which pages it is used?
    Thanks in advance for guiding me there ...
    bye,
    Beate

    > How do DW users know how often and where an image is
    used on the site
    > then?
    I'm not sure what the benefit is of knowing how often an
    image is used, but
    a search for the image by filename would do the trick.
    And just so you'll know, this is a peer forum, not an
    official communication
    vehicle to Adobe. We are all just users here, not Adobe
    employees.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "beatrice" <[email protected]> wrote in
    message
    news:[email protected]...
    > OK. I sent the below feature request.
    > How do DW users know how often and where an image is
    used on the site
    > then?
    > always doing a find/search?
    > in GoLive there was an simple window where all the files
    a page consisted
    > of
    > were listed plus all the files that were pointing to
    that page. such,
    > without
    > having to open a page links and image and componentes
    etc. could be
    > changed via
    > point&shoot.
    >
    > Couldn't you all think of this a being great and helpful
    and making site
    > management easy? Then send in a feature request as well,
    please.
    >
    > ...............
    > How can one know by the assets or files list if an image
    is used at all on
    > the
    > site?
    > and how many times? and on which pages?
    > This is very useful to know especially in larger sites.
    > e.g. an image should get changed on one page, now it
    would be very good to
    > see
    > if when it was used on other pages as well if it would
    make still sense
    > there
    > when changed.
    > as DW can update files (when e.g. an image name gets
    changed) there is a
    > way
    > this is already recorded. why not take this records and
    send this back
    > into a
    > list/column in the files panel to indicated that the
    image is used and
    > how
    > many times.
    > plus to have another window that can display all the
    pages the image is
    > used
    > in.
    > so one could click through all those pages and open them
    to check the
    > image
    > there.
    > in GoLive that feature was called 'In and Out links' and
    one could see a
    > page
    > in the middle and left and right from it many
    branches/lines at which ends
    > the
    > filenames were visible used in that page.
    > so one e.g. could also point and shoot from this list
    and change a file or
    > image or component simply by point and shooting to the
    files panel without
    > having to open the pages.
    > These features were so practical for an effective daily
    workflow that I
    > don't
    > understand why they haven't been put into cool DW yet.
    Please, please do
    > so in
    > the next release. I can test it thoroughly if you need
    testers for it.
    > bye,
    > beate
    >

  • When I adjust an image I used to have a little icon on the bottom right of the image in the browser viewer indicating that the image had been adjusted. These icons are gone. How can i get them back?

    When I adjust an image I used to have a little icon on the bottom right in browser view indicating that the image was adjusted. These icons are gone now. How do I get them back?

    https://discussions.apple.com/message/15285822#15285822

  • Problem in mobile phone camera Image retrieval using J2ME ...

    Hi
    I am doing video surveillance application with mobile phone ...
    but i am not able to get the images faster from my mobile phone ..
    I need atleast 2 photos /frames per second using J2ME ...
    wen i tried it , it is very slow and i am not able to get 2 frames per second ...
    can somebody help me ?

    That's quite a bunch of stuff you want to do there.
    Just a short hint for the image processing part here: You can ask any BufferedImage for it's raster (using getRaster()), and you can use the raster's getData() method to access the DataBuffer (the array storing the pixel values). It should be quite easy to split the DataBuffer into 9 tiles which you can then store as blobs. You can also use the DataBuffer to check for color values, or, if you don't want the trouble, you can always use the raster's getRBG(...) method - beware though, it's a lot slower for processing large quantities of pixels. Just another hint: you will have to cast the DataBuffer to it's real type if you want to access the pixel values, for example to DataBufferByte for most RGB images. You can use the DataBuffer's getType() method to determine which kind of buffer the image is using.

  • Determining image types used in pdf

    Hi,
    I was sent a pdf by a client and was wondering if there was a way to determine what types of images he used in the file.
    For example, did he use .jpg, .tif,, .eps etc.
    Thanks,
    Andrew Hutton
    [signature deleted by host]

    In the Object palette make sure Embed Image Data is ticked.

Maybe you are looking for