aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Logical operation on Image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Logical operation on Image" Watch "Logical operation on Image" New topic
Author

Logical operation on Image

sachin upatil
Greenhorn

Joined: May 17, 2010
Posts: 29

In Java How to do logical operation on Image ?

e.g ANDing, ORing ....
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

What do you want to achieve exactly? Take the (A)RGB value of each pixel (x,y) in both images, perform the operation on those two values, then set the result of that operation for a new image?

If so, look at BufferedImage. It allows you to get and set individual pixel values using getRGB and setRGB. Use ImageIO.read to create BufferedImage objects from files.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

What do you want to achieve exactly?

Whatever it is he wants, it's probably achievable with AlphaComposite or BlendComposite. If so, there's no need to reinvent the wheel (unless of course if this is homework).

luck, db
There are no new questions, but there may be new answers.
sachin upatil
Greenhorn

Joined: May 17, 2010
Posts: 29
I want to do this logical operation (as shown in image screenshot) on binary image ?

I did it using BufferedImage. I take the each pixel from two images and do logical operation on that pixel and setting that pixel.(used getRGB and setRGB).
the result i get attached as LogicalOPeration.

what's wrong with AND and OR operation in my result ?



[Thumbnail for Screenshot.png]


[Thumbnail for LogicalOperation.PNG]

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

Now we see what you want, AlphaComposite is what you should use. If we define IMG_1 as the source and IMG_2 as the destination, you can use the following rules:
- SRC_IN for AND
- SRC_OVER for OR
- CLEAR for XOR
- DST_OUT for NOT-AND
sachin upatil
Greenhorn

Joined: May 17, 2010
Posts: 29
Problem solved ....

First i converted image as Binary : if getRGB if RGB = 255: pixel = 0 else 1

Do operation on it then setRGB() : if result 1 = setRGB black else white.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Logical operation on Image