i had been working on my project which encompasses the technique for comparing images. I want to compare two images in java in terms of height and width, i can't compare it if any one can help it please do..
Asked
Active
Viewed 429 times
1 Answers
0
Here is a head start. You can use something like this and that should get you going.
Image image;
public static void listFilesForFolder(File folder) {
for (final File fileEntry : folder.listFiles()) {
Image image;
try {
image = ImageIO.read(new File("C://Users//workspace//ImageProcessing//images//" + fileEntry.getName()));
BufferedImage buffered = (BufferedImage) image;
int imageHeight = image.getHeight(null);
int imageWidth = image.getWidth(null);
yourImageClass.setHeight(imageHeight);
yourImageClass.setWidth(imageWidth);
arrayListOfImageClasses.add(yourImageClass);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(fileEntry.getName());
}
}
These are the jars you can use :
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
Hope this gets you going.

Pritam Banerjee
- 17,953
- 10
- 93
- 108
-
actually i have to capture frames from a specified video and compare that frames with each other to find the portion wise difference between them .... will the above code be usefull. for that??? – Shubham Jan 21 '16 at 18:08
-
Yes, it will be. You need to get the frames and then compare the size of the frames. – Pritam Banerjee Jan 21 '16 at 18:25
-
how to compare them ?? how to pass the path of two images simultaneously??? – Shubham Jan 21 '16 at 18:37
-
It is easy. Write a function that reads the images. Then create a class Image with two attributes - height and width. When you read through the files you keep adding the Images to an ArrayList. Then do comparisons in whatever way you want. I have edited my code to give you some hints. – Pritam Banerjee Jan 21 '16 at 18:54
-
-
-
-
it says method not found..... while executing setwidth and setheight method. – Shubham Jan 28 '16 at 14:46
-
-
-
What error did it throw ? And what Java version are you using ? – Pritam Banerjee Jan 29 '16 at 17:55
-
i am using jdk 1.8. It states as "cannot find symbol " on line where we declared the setheight and setwidth method.... Also says "Illegal start of expression" at method declaration of "public static void listFilesForFolder(File folder) ". – Shubham Jan 30 '16 at 05:35
-
i am trying naivesimilarity program from java cookbook bt couldn't get the dissimilar image .... can anyone help me on that.??? – Shubham Feb 03 '16 at 16:23