ImageMagick along with Im4Java

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
appu
Posts: 29
Joined: 2013-09-20T10:10:02-07:00
Authentication code: 6789

ImageMagick along with Im4Java

Post by appu »

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

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();
		}		
	}
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 ?

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)
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
payshah
Posts: 1
Joined: 2014-04-09T14:43:10-07:00
Authentication code: 6789

Re: ImageMagick along with Im4Java

Post by payshah »

Did this work for you? I am facing similar problem and getting same exception..

Thanks..
Post Reply