• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Logical operation on Image  RSS feed

 
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 ....
 
Sheriff
Posts: 21503
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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.
 
Bartender
Posts: 5167
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
[Thumbnail for Screenshot.png]
Logical operation on Image
LogicalOperation.PNG
[Thumbnail for LogicalOperation.PNG]
the result which i get..
 
Rob Spoor
Sheriff
Posts: 21503
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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.


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!