ImportDialog: raw format heuristics on byte order

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ImportDialog: raw format heuristics on byte order

Adrian Daerr-2
Hello,

The ImportDialog for raw image data inspects the file name and the file
size to guess values for some of the fields required by the import
dialog. In this process, the endianness is set quite arbitrarily to
"true" except if the filename ends in "be.raw" [*].  Why not leave the
value to that set in the preferences ?

Specifically, I'd like to suggest that the method guessFormat of the
ImportDialog class be patched as below (lines starting with "-" deleted,
lines starting with "+" added).

--- guessFormat_current 2018-04-08 07:02:16.921211374 +0200
+++ guessFormat_suggested       2018-04-08 07:06:19.545464541 +0200
@@ -5,14 +5,15 @@
          long fileSize = file.length();
          if (fileSize==4*imageSize) {
              choiceSelection = 5; // 32-bit real
-            intelByteOrder = true;
          } else if (fileSize==2*imageSize) {
              choiceSelection = 2;    // 16-bit unsigned
-            intelByteOrder = true;
          } else if (fileSize==3*imageSize) {
              choiceSelection = 7;    // 24-bit RGB
          } else if (fileSize==imageSize)
              choiceSelection = 0;    // 8-bit
+        // Check for hint regarding endianness
          if (name.endsWith("be.raw"))
              intelByteOrder = false;
+        else if (name.endsWith("le.raw"))
+            intelByteOrder = true;

With this modification the endianness setting is modified only if an
explicit hint is detected, which seems a little less invasive than the
current behaviour. After all the endianness is saved in the preferences,
so we may just as well assume that the user already set it to the
correct value, and not overwrite it for no reason.

Does this make sense ?
cheers,
Adrian




[*] View the current code at
https://imagej.nih.gov/ij/developer/source/ij/io/ImportDialog.java.html#324

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: ImportDialog: raw format heuristics on byte order

Miettinen, Arttu
Hello everybody,

Feeling partially guilty of probably originally asking for this "invasive behaviour", I would like to express my support to Adrian's suggestion. If you end up editing the ImportDialog.java, I would also remove lines
"if (w<10) return;"
and
"if (h<10) return;"
from getDimensionsFromName method unless you see that inducing some unwanted behaviour. The reason for this is that I'm often using .raw images with small width and height, and those two lines disable the dimension guessing procedure for the small files.

Best regards,
Arttu


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Adrian Daerr
Sent: Sonntag, 8. April 2018 07:27
To: [hidden email]
Subject: ImportDialog: raw format heuristics on byte order

Hello,

The ImportDialog for raw image data inspects the file name and the file size to guess values for some of the fields required by the import dialog. In this process, the endianness is set quite arbitrarily to "true" except if the filename ends in "be.raw" [*].  Why not leave the value to that set in the preferences ?

Specifically, I'd like to suggest that the method guessFormat of the ImportDialog class be patched as below (lines starting with "-" deleted, lines starting with "+" added).

--- guessFormat_current 2018-04-08 07:02:16.921211374 +0200
+++ guessFormat_suggested       2018-04-08 07:06:19.545464541 +0200
@@ -5,14 +5,15 @@
          long fileSize = file.length();
          if (fileSize==4*imageSize) {
              choiceSelection = 5; // 32-bit real
-            intelByteOrder = true;
          } else if (fileSize==2*imageSize) {
              choiceSelection = 2;    // 16-bit unsigned
-            intelByteOrder = true;
          } else if (fileSize==3*imageSize) {
              choiceSelection = 7;    // 24-bit RGB
          } else if (fileSize==imageSize)
              choiceSelection = 0;    // 8-bit
+        // Check for hint regarding endianness
          if (name.endsWith("be.raw"))
              intelByteOrder = false;
+        else if (name.endsWith("le.raw"))
+            intelByteOrder = true;

With this modification the endianness setting is modified only if an explicit hint is detected, which seems a little less invasive than the current behaviour. After all the endianness is saved in the preferences, so we may just as well assume that the user already set it to the correct value, and not overwrite it for no reason.

Does this make sense ?
cheers,
Adrian




[*] View the current code at
https://imagej.nih.gov/ij/developer/source/ij/io/ImportDialog.java.html#324

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: ImportDialog: raw format heuristics on byte order

Wayne Rasband-2
In reply to this post by Adrian Daerr-2
> On Apr 8, 2018, at 1:26 AM, Adrian Daerr <[hidden email]> wrote:
>
> Hello,
>
> The ImportDialog for raw image data inspects the file name and the file size to guess values for some of the fields required by the import dialog. In this process, the endianness is set quite arbitrarily to "true" except if the filename ends in "be.raw" [*].  Why not leave the value to that set in the preferences ?

In the latest daily build (1.52a46), with ".raw" files with dimensions encoded in the name (e.g. "myfile-640x480.raw"), the byte order is set to big-endian if the name ends in "be.raw" and to little-endian if it ends in "le.raw”. If the byte order is not specified, it defaults to the value set in the preferences. Also in the daily build, the width and height encoded in the name can be less than 10.

-wayne

> Specifically, I'd like to suggest that the method guessFormat of the ImportDialog class be patched as below (lines starting with "-" deleted, lines starting with "+" added).
>
> --- guessFormat_current 2018-04-08 07:02:16.921211374 +0200
> +++ guessFormat_suggested       2018-04-08 07:06:19.545464541 +0200
> @@ -5,14 +5,15 @@
>         long fileSize = file.length();
>         if (fileSize==4*imageSize) {
>             choiceSelection = 5; // 32-bit real
> -            intelByteOrder = true;
>         } else if (fileSize==2*imageSize) {
>             choiceSelection = 2;    // 16-bit unsigned
> -            intelByteOrder = true;
>         } else if (fileSize==3*imageSize) {
>             choiceSelection = 7;    // 24-bit RGB
>         } else if (fileSize==imageSize)
>             choiceSelection = 0;    // 8-bit
> +        // Check for hint regarding endianness
>         if (name.endsWith("be.raw"))
>             intelByteOrder = false;
> +        else if (name.endsWith("le.raw"))
> +            intelByteOrder = true;
>
> With this modification the endianness setting is modified only if an explicit hint is detected, which seems a little less invasive than the current behaviour. After all the endianness is saved in the preferences, so we may just as well assume that the user already set it to the correct value, and not overwrite it for no reason.
>
> Does this make sense ?
> cheers,
> Adrian
>
>
>
> [*] View the current code at
> https://imagej.nih.gov/ij/developer/source/ij/io/ImportDialog.java.html#324

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: ImportDialog: raw format heuristics on byte order

Adrian Daerr-2
On 04/12/2018 05:55 AM, Wayne Rasband wrote:
> In the latest daily build (1.52a46), with ".raw" files with dimensions encoded in the name (e.g. "myfile-640x480.raw"), the byte order is set to big-endian if the name ends in "be.raw" and to little-endian if it ends in "le.raw”. If the byte order is not specified, it defaults to the value set in the preferences. Also in the daily build, the width and height encoded in the name can be less than 10.

Perfect, thank you Wayne!
Adrian

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html