Image Analysis with ImageJ

Extensible Persistent Properties for ImageJ Images

 

Here was a very interesting addition, made by Wayne Rasband to Image J 1, to add a feature.

On Apr 15, 2020, at 3:03 PM, Michael Ellis <michael.ellis@DSUK.BIZ> wrote:
>
> Michael,
>
> Many thanks!

> Mindful of your reply, I think I will go forward with hijacking the “Info” property then, even though it seems like an awful hack.
>
> Just before I do though, is there any hope, or reason that ImageJ 1 could be enhanced to save and restore just the properties of type String?
The ImageJ 1.53a3 daily build adds setProp() and getProp() methods for saving and restoring string properties. The following JavaScript demonstrates how to use these new methods. Since they only work with strings, it also shows how to encode non-string objects, such images, into strings.
-wayne

img = IJ.createImage(“Untitled”, “8-bit black”, 500, 500, 3);
clown = IJ.openImage(“http://wsr.imagej.net/images/clown.jpg&#8221;);

bytes = new FileSaver(clown).serialize();
string = Base64.getEncoder().encodeToString(bytes);
img.setProp(“clown”, string);
text = “Clown.jpg was serialized, set as an image\n”
+ “property, the image was saved, re-opened,\n”
+ “and clown.jpg was deserialized and displayed.”;
img.setProp(“text”, text);
path = IJ.getDir(“home”)+”Downloads/Untitled.tif”;
IJ.saveAs(img, “Tiff”, path);
img2 = IJ.openImage(path);
string2 = img2.getProp(“clown”);
bytes2 = Base64.getDecoder().decode(string2);
clown2 = new Opener().deserialize(bytes2);
clown2.show();
IJ.showMessage(img2.getProp(“text”));
> As far as I can see this would:
>
>   – Have no compatibility issues.
>   – Offer the functionality of extensible  persistent properties without any API changes.
>   – Arbitrary data could be saved as JSON or XML (as indeed the existing “Info” property does for native BioFormats OME.TIFF
>
> Would such a change be considered for inclusion, and if so how?
> How would I find out if it would be included if I were to implement it?
>
> ALSO
>
> I have spent a lot of time trying to use ImageJ 2. In the end I gave up, for as wonderful as it might be, it managed to confound my every attempt to work with it.
>
>   – I could not make it play nice with Java 11 and modules, the worked example just do not work with Java 11
>   – The extensive use of advanced Java facilities confused my small brain:
>      – Generics, Annotations, Lambda’s to a lesser extent, all feel like layer language features. To me they make what was originally a simple language ugly. Whilst these features may well offer advantages for large scale development, they also crush my creativity and imagination and rob me of the will to live when attempting to do simple things.
>   – Maven seems like a dark art for but the simplest things, and trying to find the right dependencies sent me round in circles
>   – there seems even less documentation that there is for ImageJ 1
>
> I do not mean to be criticising off ImageJ2, I am sure it is amazingly good, but for the uninitiated, it was just impenetrable.
>
> I also wanted to save 5D image files easily, and started with Bio-Formats, but again have given up on that for similar reasons: huge, complex, does not play nice wit Java 11 (things like module conflicts), hence looking at ImajeJ1 to that for me.
>
> Is there a plan future plan for ImageJ1, I remember going from the NIH  Image t ImageJ, and that was great. I wonder if anyone would like to take on an ImageJ rewrite in Python with an eye to the incredible promises on offer from Oracle  GraalVM or any other way forward that keeps things simple, and attractive, making it seductive for scientist rather than heavy duty computer scientists?
>
>
>
>> On 15 Apr 2020, at 17:52, Michael Schmid <schmid@IAP.TUWIEN.AC.AT>

wrote:
>>
>> Hi Michael
>>
>> maybe an incomplete answer, but better than no answer:
>>
>> – I guess that the ‘info’ String will remain there for as long as we have ImageJ.
>> – At least in ImageJ1, I am not aware of any convention to avoid duplicate keywords.
>> – The reason why other ImagePlus properties are not saved is probably that (i) the lack of a mechanism to save and read them (they can be any type of object; java serialization would not guarantee that they can be read at a later stage when the code of the class changes) and (ii) one might store objects for temporary use in the properties.
>>
>>
>> Michael
>> ________________________________________________________________
>> On 15.04.20 15:58, Michael Ellis wrote:
>>> I’m using ImageJ 1.52 as a Java library. for my own Java application.
>>> I create images that are to be saved and restored. I want to attach extra information to an ImagePlus that will be persisted and restored using the standard ImageJ open and save operations.
>>> I’ve discovered that only some specific ImagePlus  properties are persisted with the default ImageJ file operations (such as  the “Info” property)
>>> The “Info”, appears itself to be a string formatted in a manor that is itself a list of properties. Can I safely append more (sub) properties to this “Info” property and expect them to be safel honoured by future versions of ImageJ 1.xx?
>>> The code below does what I want, but is it future safe?
>>> Also why are not all ImagePlus properties persisted?
>>> Is there some other mechanism for save augmenting an Image in ImageJ with extensible metadata that I am missing?
>>> I intend to add my extra properties with a reverse domain name notation key to avoid accidental clashes.
>>>    /**
>>>     * Adds a key-value pair to this ImagePlus’s Info properties. The key is
>>>     * removed from the properties table if value is null.
>>>     *
>>>     * @param imagePlus
>>>     * @param key
>>>     * @param value
>>>     * @throws IOException
>>>     * @see #getInfoProperties
>>>     */
>>>    void setInfoProperty(ImagePlus imagePlus, String key, String value) throws IOException {
>>>        Properties infoProperties = getInfoProperties(imagePlus);
>>>        if (value == null) {
>>>            infoProperties.remove(key);
>>>        } else {
>>>            infoProperties.setProperty(key, value);
>>>        }
>>>        StringWriter sw = new StringWriter();
>>>        infoProperties.store(sw, null);
>>>        imagePlus.setProperty(“Info”, sw.toString());
>>>    }
>>>    /**
>>>     * Get a property from an ImagePlus’s Info properties.
>>>     *
>>>     * @param imagePlus
>>>     * @param key
>>>     * @return the
>>>     * @see #getInfoProperties
>>>     */
>>>    String getInfoProperty(ImagePlus imagePlus, String key) throws IOException {
>>>        return getInfoProperties(imagePlus).getProperty(key);
>>>    }
>>>    /**
>>>     * Get the specified ImagePlus’s Info properties. The “Info” properties are
>>>     * a list of properties nested within the ImagePlus’s property indexed with
>>>     * the key value “Info”. ImagePlus’s “Info” property is saved and restored
>>>     * by the default ImagePlus save and open operations.
>>>     *
>>>     * @param imagePlus
>>>     * @param key
>>>     * @return the
>>>     */
>>>    Properties getInfoProperties(ImagePlus imagePlus) throws IOException {
>>>        Properties infoProps = new Properties();
>>>        infoProps.load(new StringReader((String) imagePlus.getProperty(“Info”)));
>>>        return infoProps;
>>>    }

 

 

 


Test Upload from Windows Live Writer

This is to test connection from windows live writer


Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!