Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logical operation on Image

 
sachin upatil
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In Java How to do logical operation on Image ?

e.g ANDing, ORing ....
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
sachin upatil
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
Screenshot.png
Logical operation on Image
[Thumbnail for Screenshot.png]
LogicalOperation.PNG
the result which i get..
[Thumbnail for LogicalOperation.PNG]
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic