Page 1 of 1

Opening SCN file in MATLAB

PostPosted: Thu Jun 21, 2018 6:58 pm
by jyotani
How do I get MATLAB to read ImageLab format (.scn) file?

I checked the documentation (https://docs.openmicroscopy.org/bio-formats/5.8.2/formats/bio-rad-scn.html) but not sure how to use the Java source code.

Following is the command and output of the imreadBF code that I am getting:

Command:
imreadBF('A.scn','SCN')

Output:
path =

C:\Users\jyot.antani\Documents\MATLAB\MATLAB files_Jyot\loci_tools.jar

Warning: Objects of loci/formats/UnknownFormatException class exist - not clearing java
> In javaclasspath>local_javapath (line 190)
In javaclasspath (line 119)
In javaaddpath (line 71)
In imreadBF (line 31)

Error using imreadBF (line 58)
Java exception occurred:
loci.formats.UnknownFormatException: Unknown file format: A.scn

at loci.formats.ImageReader.getReader(ImageReader.java:192)

at loci.formats.ImageReader.setId(ImageReader.java:727)

at loci.formats.ReaderWrapper.setId(ReaderWrapper.java:529)

at loci.formats.ChannelFiller.setId(ChannelFiller.java:263)

at loci.formats.ReaderWrapper.setId(ReaderWrapper.java:529)

at loci.formats.ChannelSeparator.setId(ChannelSeparator.java:274)


Can someone please help?
Thanks!

Re: Opening SCN file in MATLAB

PostPosted: Thu Jun 21, 2018 9:03 pm
by sbesson
Hi,

could you tell us more about the imreadBF function you are using? Is it the one available from https://uk.mathworks.com/matlabcentral/ ... ile-format?

Could you also give us the version of the Bio-Formats library you are using as reported by:

Code: Select all
disp(char(loci.formats.FormatTools.VERSION))


Best,
Sebastien

Re: Opening SCN file in MATLAB

PostPosted: Thu Jun 21, 2018 10:57 pm
by jyotani
Hi Sebastian,

Yes that is the imreadBF file I am using.

Seems like the Bio-Formats version is the culprit.

Code: Select all
disp(char(loci.formats.FormatTools.VERSION))
Undefined variable "loci" or class "loci.formats.FormatTools.VERSION".


What I did was I downloaded the Bio-Formats zipped folder bfmatlab and unzipped on my MATLAB path. Do I need to do something more?

Thanks,
Jyot

Re: Opening SCN file in MATLAB

PostPosted: Fri Jun 22, 2018 1:35 pm
by sbesson
Hi Jyot,

Seems like the Bio-Formats version is the culprit.

Code: Select all
disp(char(loci.formats.FormatTools.VERSION))
Undefined variable "loci" or class "loci.formats.FormatTools.VERSION".


What I did was I downloaded the Bio-Formats zipped folder bfmatlab and unzipped on my MATLAB path. Do I need to do something more?


The error below tells you that the Bio-Formats JARs are not on the Java classpath. If you have downloaded the latest Bio-Formats MATLAB toolbox, you should be able to put these JARs on the classpath and return the version of the library via:

Code: Select all
[status,version] = bfCheckJavaPath()


Assuming you have done the above and are running the latest version (currently 5.8.2), could you check that the toolbox functions return the same behavior as your imreadBF function e.g. by executing:

Code: Select all
data = bfopen('A.scn');


If the above still reports an error message, we might need a sample file to help you further with this issue

Best,
Sebastien

Re: Opening SCN file in MATLAB

PostPosted: Sat Jul 07, 2018 5:00 am
by jyotani
Sebastian,

I employed [status,version] = bfCheckJavaPath(), verified that the version is indeed 5.8.2. Now imreadBF is giving me a different set of warnings and errors:

Code: Select all
path =

C:\Users\jyot.antani\Documents\MATLAB\MATLAB files_Jyot\loci_tools.jar

Warning: Objects of loci/formats/ome/OMEXMLMetadataImpl class exist - not clearing java
> In javaclasspath>local_javapath (line 190)
  In javaclasspath (line 119)
  In javaaddpath (line 71)
  In imreadBF (line 31)
Not enough input arguments.

Error in imreadBF (line 71)
channel=channel-1;


However, I tried data = bfopen('A.scn');
data{1,1}{1,1} is indeed returning the image. My requirement of getting MATLAB to read the image is fulfilled.

Thanks for your help! Let me know if there is a better way of doing this.

Regards,
Jyot

Re: Opening SCN file in MATLAB

PostPosted: Mon Jul 09, 2018 8:28 am
by sbesson
Hi Jyot,

thanks for letting us know of the successful outcome.

If loading all the planes at once is acceptable for you, then the bfopen function should be functionally equivalent to imreadBF. For large multi-dimensional images, you might need to use more fine-grained functions like bfGetReader and bfGetPlane to load only a subset of planes or tiles - see the technical documentation for more details.

Best,
Sebastien

Re: Opening SCN file in MATLAB

PostPosted: Mon Jul 09, 2018 3:16 pm
by jyotani
Sebastian,

I can read the image and save it as tiff, thanks for your help with that.

Now I would like to optimize the performance: please look at the attached files. My original image is A.scn (attached). I am using the following code to convert it to A.scn.tif (attached).

Code: Select all
filename = 'A.scn';
data = bfopen(filename);
im = data{1,1}{1,1};
im = imcomplement(im);
imwrite2tif(im,[],[filename '.tif'],'uint16')


This is saving a file, which I can open using ImageJ, and it looks fine. However, when I open it using the Windows Photo Viewer or any microsoft office document (MS Word or MS Powerpoint), it looks very white. Snapshot attached.

My aim is to get the image that looks like A.tif (attached), which I generated using the Image Lab software provided by Bio-Rad. I inverted the original image A.scn (theoretically the same function as imcomplement) and then exported for publication at 300dpi.

Differences are:
A.tif: Size = 1985x2480x4, Bytes = 19691200, Class = uint8
A.scn.tif: Size = 2208x2758, Bytes = 12179328, Class = uint16

So I apparently need to convert the original image into a 4-layer tif, but I am not sure how to do that using the bfopen and imwrite2tif codes that I have at my disposal. Could you please help with this?

Thanks,
Jyot

Attachments: https://drive.google.com/open?id=1JrH_h ... dT212MXHcj

Re: Opening SCN file in MATLAB

PostPosted: Tue Jul 10, 2018 2:17 pm
by dgault
Hi Jyot,

I believe the difference you are seeing between the two tiff files is likely due to the difference in pixel values (one being uint8 and the other uint16) rather than the channels. The uint16 is the same as the original scn file which would appear correct, this does result in much higher pixel values when you perform the inversion and may affect the appearance of the autoscaling for some applications.

The uint16 values are a match for the original pixel data, however if you wish to have uint8 values then converting the image data in MATLBA before performing the imcomplement function should give the same result. This could be done using the im2uint8 function as in https://uk.mathworks.com/help/images/ref/im2uint8.html

David Gault