0

I tried to replace the white background of an image with a transparent one using the below lines,

IMOperation op = new IMOperation();
op.fuzz(0.20,true);
//op.transparent("white");
op.addImage("C:\\write\\test.png");
op.addImage("C:\\test\\result.png");
ConvertCmd cmd =new ConvertCmd();
cmd.run(op);

but I'm getting an error - invalid parameter 0.2%

Can someone help here?

quant
  • 2,184
  • 2
  • 19
  • 29
  • Sorry, I know little about im4java. But you commented out the line that tells fuzz what color to work on. Try uncommenting it. Also you likely need to read your input image into op before trying to process. So move that line after creating the new operation. Also you appear to addImage on your output. That does not seem correct to me. I think you need to review the im4java documentation about writing to output, which should come after processing. In command line, the command would be `convert test.png -fuzz 20% -transparent white PNG32:result.png`. Assumes test.png is not already transparent. – fmw42 Nov 15 '18 at 06:43
  • At which point do you get this error? At `op.fuzz(0.20, true);` or `cmd.run(op);`? `im4java` is just a wrapper, do you expect it to build command `-fuzz 0.2%` or `-fuzz 20%`? – barbsan Nov 15 '18 at 07:34
  • @fmw42, Thank you for the above comments. I tried rearranging the order as you suggested, but still I get the error in the immediate next line after adding "test.png". The error is "Invalid parameter - fuzz". Do you have any thoughts? – sugeetha R Nov 15 '18 at 08:43
  • @barbsan, I'm getting command Exception at cmd.run(op); – sugeetha R Nov 15 '18 at 08:47
  • How many colors are there in your image? According to command fuzz's [docs](http://www.imagemagick.org/script/command-line-options.php?#fuzz) for 256 (max intensity 255) you may request 255*0.002 = 0.51 so 0.2% propably would be too low value – barbsan Nov 15 '18 at 08:50
  • My image has a shirt with single blue color and white background. I need to make the shirt color remain as it is and remove the white background by making it transparent. – sugeetha R Nov 15 '18 at 08:57
  • If the values in your image vary between 0..255, you should maybe try a fuzz of 64, or even higher till you get a result. – Mark Setchell Nov 15 '18 at 15:28
  • Thank u all for your comments. Finally I was able to sort out the issue! – sugeetha R Nov 19 '18 at 10:08

0 Answers0