Scale to DPI seems to be broken
CanYing0913 opened this issue · 4 comments
Hi there, I have a tiff image and I'd like to use Scale To DPI
feature so that I can save them to >=300 DPI. Currently when I save it, its DPI is only 120.
But Scale To DPI
seems to be broken:
[ERROR] java.lang.NullPointerException
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:57)
at sun.reflect.UnsafeIntegerFieldAccessorImpl.getInt(UnsafeIntegerFieldAccessorImpl.java:56)
at sun.reflect.UnsafeIntegerFieldAccessorImpl.get(UnsafeIntegerFieldAccessorImpl.java:36)
at java.lang.reflect.Field.get(Field.java:393)
at java.lang.invoke.MethodHandleImpl$BindCaller$T/752667271.invoke_V(MethodHandleImpl.java:1258)
at jdk.nashorn.internal.scripts.Script$Recompilation$21$2990A$Scale_to_DPI.getFieldValue(Image/Adjust/Scale_to_DPI.js:91)
at jdk.nashorn.internal.scripts.Script$Recompilation$20$515$Scale_to_DPI.scaleToDPI(Image/Adjust/Scale_to_DPI.js:30)
at jdk.nashorn.internal.scripts.Script$18$Scale_to_DPI.:program(Image/Adjust/Scale_to_DPI.js:17)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:449)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402)
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at org.scijava.script.ScriptModule.run(ScriptModule.java:173)
at org.scijava.module.ModuleRunner.run(ModuleRunner.java:165)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:125)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:64)
at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:247)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
Any help is appreciated. Thanks.
Thanks @CanYing0913 for the report! This problem happens on my machine as well. Investigating now.
@CanYing0913 An internal field was renamed in ImageJ 1.53n, which broke the script. I added some logic to deal with the situation. Can you update your Fiji and try again?
@ctrueden Thanks now it works. As a follow-up question I want to ask, are there any differences between dpi unit? I scaled my tiff image to 600 DPI in Fiji and export to png file. However, when I inspect the png file, it still shows 120 DPI. (The file size also indicates it is not likely to be 600 DPI since I created another 600 DPI image using photoshop yesterday)
@CanYing0913 Probably the PNG saver is not storing physical calibration metadata. Nor does ImageJ/Fiji itself really have the concept of DPI, exactly: but it does have physical calibration in whatever unit you want, which could be inches.
The "Scale to DPI" command is really just a simple helper to resize an image to the number of pixels needed to reflect the requested width x height in inches at the specified DPI. You can read the code to see what I mean...
This SO thread might be of interest: https://stackoverflow.com/q/27323561/1207769