ImageMagick along with Im4Java
Posted: 2013-09-20T11:02:34-07:00
I am new to ImageMagick and Im4Java. For my project purpose, I've installed ImageMagick-6.8.6-Q16 in my win 7 32 bit machine. I used Im4Java-1.4.0.
I need to do image comparison using Normalized Cross Correlation(NCC). The command line try with IMagick works fine for the following command
compare -metric NCC expected.jpg actual.jpg null:2>1&
Code snippet
Through experiments, exit code greater than 0.9 is considered as match. But even if I supplied identical images, always it throws IM4JavaException as below and return the exit code correctly in the stack trace. Is it an expected behaviour of Im4Java or is it a bug ? Is there any ways to specify the threshold to match in Compare operation ?
Also I need to do the grayscaling and then do the comparison. Is there any way to do multiple operation in a single command run im4java ?
Please help me to resolve these issues. Thanks in Advance.
-Appu
I need to do image comparison using Normalized Cross Correlation(NCC). The command line try with IMagick works fine for the following command
compare -metric NCC expected.jpg actual.jpg null:2>1&
Code snippet
Code: Select all
public void compare(File actual, File expected) throws Exception {
arguments.add("-metric");
arguments.add(Metric.NCC.name());
operation = new IMOperation();
operation.addRawArgs(arguments);
operation.addImage(actual.getAbsolutePath());
operation.addImage(expected.getAbsolutePath());
operation.addImage("output.jpg");
ImageCommand compare = new ImageCommand();
compare.setOutputConsumer(output);
compare.setCommand("compare");
try {
compare.run(operation);
} catch (IOException | InterruptedException e) {
throw e;
} catch (IM4JavaException e) {
e.printStackTrace();
}
}
Code: Select all
Caused by: org.im4java.core.CommandException: [b]0.866473[/b]
at org.im4java.core.ImageCommand.finished(ImageCommand.java:253)
at org.im4java.process.ProcessStarter.run(ProcessStarter.java:314)
at org.im4java.core.ImageCommand.run(ImageCommand.java:215)
Please help me to resolve these issues. Thanks in Advance.
-Appu