Hallo! To read uncompressed TIFF files I use the freeimage plugin. The reading works great but since last week I need to save a summed Image. I used the io.imsave() with the freeimage plugin but by default it writs a compressed TIFF file. The freeimage documentation provides Flags to use for different compressions or for a non compressed type (TIFF_NONE). Can someone tell me how to pass theses Flags to the plugin? I saw that Christophs 'tifffile' plugin does the job but still I would like to know how to use the freeimage plug-n for it.
Thanks!
Siggi
Hi Siggi,
This functionality is not exposed by the imsave() apparatus, but can be accessed by the image writing functions in the plugin that imsave() calls.
A quick scan through the source code is likely to be the most helpful thing, regarding the available flags, etc: https://github.com/scikits-image/scikits-image/blob/master/skimage/io/_plugi...
In particular, the freeimage_plugin.write() function, around which freeimage_plugin.imsave() is a thin wrapper, allows you to set various flags. So: import skimage.io._plugins.freeimage_plugin as fi image = fi.read('/path/to/whatever') fi.write(image, 'whatever.tif', fi.IO_FLAGS.TIFF_NONE)
Zach
On May 12, 2012, at 4:04 AM, Sigmund wrote:
Hallo! To read uncompressed TIFF files I use the freeimage plugin. The reading works great but since last week I need to save a summed Image. I used the io.imsave() with the freeimage plugin but by default it writs a compressed TIFF file. The freeimage documentation provides Flags to use for different compressions or for a non compressed type (TIFF_NONE). Can someone tell me how to pass theses Flags to the plugin? I saw that Christophs 'tifffile' plugin does the job but still I would like to know how to use the freeimage plug-n for it.
Thanks!
Siggi
Hallo!
As I wrote, the workaround:
Am Samstag, 12. Mai 2012 15:47:10 UTC+2 schrieb Zachary Pincus:
import skimage.io._plugins.freeimage_plugin as fi fi.write(image, 'whatever.tif', fi.IO_FLAGS.TIFF_NONE)
by Zach worked fine for me. Now I tried the same code on a WIN 7 64 bit system (EPD 7.3.1) and got the following error:
Traceback (most recent call last): File "G:\Marwen\Summer.py", line 67, in <module> fi.write(summation, str(datensatz)+"_interval-"+str(interval_length)+"_"+str(count)+'.tif', fi.IO_FLAGS.TIFF_NONE) File "C:\Python27\lib\site-packages\skimage\io_plugins\freeimage_plugin.py", line 538, in write bitmap, fi_type = _array_to_bitmap(array) File "C:\Python27\lib\site-packages\skimage\io_plugins\freeimage_plugin.py", line 604, in _array_to_bitmap raise ValueError('Cannot write arrays of given type and shape.') ValueError: Cannot write arrays of given type and shape.
I checked the .dtype of the array and compared them to the one on the 32bit and the OS X system but coutn't see any difference.
I'm reading several Images with numpy.array(io.imread(bild, plugin="freeimage"),dtype=np.int32) and sum then up one by one to write them out afterwards as one file.
Siggi
Can you save via the imsave() command? (E.g. when using compression?) That is, is this error specific to trying to use the TIFF_NONE flag, or general to saving images (or TIFF images) on Win7 64?
This may be an issue with the underlying FreeImage library, or a lingering 64-bit bug in the wrappers. So if you could do a bit more sleuthing and figure out the exact trigger for the problem, that would be very helpful in fixing it.
Thanks, Zach
On Jul 9, 2012, at 9:13 AM, Sigmund wrote:
Hallo!
As I wrote, the workaround:
Am Samstag, 12. Mai 2012 15:47:10 UTC+2 schrieb Zachary Pincus: import skimage.io._plugins.freeimage_plugin as fi fi.write(image, 'whatever.tif', fi.IO_FLAGS.TIFF_NONE)
by Zach worked fine for me. Now I tried the same code on a WIN 7 64 bit system (EPD 7.3.1) and got the following error:
Traceback (most recent call last): File "G:\Marwen\Summer.py", line 67, in <module> fi.write(summation, str(datensatz)+"_interval-"+str(interval_length)+"_"+str(count)+'.tif', fi.IO_FLAGS.TIFF_NONE) File "C:\Python27\lib\site-packages\skimage\io_plugins\freeimage_plugin.py", line 538, in write bitmap, fi_type = _array_to_bitmap(array) File "C:\Python27\lib\site-packages\skimage\io_plugins\freeimage_plugin.py", line 604, in _array_to_bitmap raise ValueError('Cannot write arrays of given type and shape.') ValueError: Cannot write arrays of given type and shape.
I checked the .dtype of the array and compared them to the one on the 32bit and the OS X system but coutn't see any difference.
I'm reading several Images with numpy.array(io.imread(bild, plugin="freeimage"),dtype=np.int32) and sum then up one by one to write them out afterwards as one file.
Siggi
same problem with io.imsave
Traceback (most recent call last): File "G:\Marwen\Summer.py", line 61, in <module> io.imsave("test.tif",summation, plugin="freeimage") File "C:\Python27\lib\site-packages\skimage\io_io.py", line 129, in imsave return call_plugin('imsave', fname, arr, plugin=plugin, **plugin_args) File "C:\Python27\lib\site-packages\skimage\io_plugins\plugin.py", line 88, in call return func(*args, **kwargs) File "C:\Python27\lib\site-packages\skimage\io_plugins\freeimage_plugin.py", line 668, in imsave write(img, filename) File "C:\Python27\lib\site-packages\skimage\io_plugins\freeimage_plugin.py", line 538, in write bitmap, fi_type = _array_to_bitmap(array) File "C:\Python27\lib\site-packages\skimage\io_plugins\freeimage_plugin.py", line 604, in _array_to_bitmap raise ValueError('Cannot write arrays of given type and shape.') ValueError: Cannot write arrays of given type and shape.
siggi
without the try: and raise ValueError in the freeimage_plugin.py it returns:
Traceback (most recent call last): File "G:\Marwen\Summer.py", line 61, in <module>io.imsave("test.tif",summation, plugin="freeimage") File "C:\Python27\lib\site-packages\skimage\io_io.py", line 129, in imsave return call_plugin('imsave', fname, arr, plugin=plugin, **plugin_args) File "C:\Python27\lib\site-packages\skimage\io_plugins\plugin.py", line 88, in call return func(*args, **kwargs) File "C:\Python27\lib\site-packages\skimage\io_plugins\freeimage_plugin.py", line 669, in imsave write(img, filename) File "C:\Python27\lib\site-packages\skimage\io_plugins\freeimage_plugin.py", line 538, in write bitmap, fi_type = _array_to_bitmap(array) File "C:\Python27\lib\site-packages\skimage\io_plugins\freeimage_plugin.py", line 601, in _array_to_bitmap fi_type = FI_TYPES.fi_types[(dtype.type, n_channels)] KeyError: (<type 'numpy.int32'>, 1)
I'm afraid that is all I can do with my limited skills...
I proved myselfe wrong ;-)
It is working if I chose numpy.float32 as dtype!
uint32 doesn't work either. Leads to KeyError: (<type 'numpy.int64'>, 1)
Siggi
Hmm, there's clearly something going wrong with int types. (There are also some failing / segfaulting tests on SPARC with int types too... I wonder if these are related?)
It is working if I chose numpy.float32 as dtype!
uint32 doesn't work either. Leads to KeyError: (<type 'numpy.int64'>, 1)
Could you provide a bit of self-contained test code (starting with creating a new numpy array with known dtype and then trying to save it) that re-creates the above error? And the full backtrace? I'm not sure how saving a uint32 array is causing a KeyError with int64 -- something odd seems to be happening there, maybe.
Zach
Hey!
Whil writing the test code I found out that saving the array by itself doesn't cause the error. Only after summing two arrays it fails.
import numpy as np import skimage.io as io io.use_plugin("freeimage", "imread") one = np.ones([2048,2048],dtype=np.int32) two = np.zeros([2048,2048],dtype=np.int32) summation = one + two io.imsave("test.tif",summation, plugin="freeimage")
not using the freeimage plugin in not failing.
Siggi
I wonder if this has to do with the type-promotion behavior changes in a recent numpy version? What is the dtype of "summation" below?
On Jul 10, 2012, at 9:35 AM, Sigmund wrote:
Hey!
Whil writing the test code I found out that saving the array by itself doesn't cause the error. Only after summing two arrays it fails.
import numpy as np import skimage.io as io io.use_plugin("freeimage", "imread") one = np.ones([2048,2048],dtype=np.int32) two = np.zeros([2048,2048],dtype=np.int32) summation = one + two io.imsave("test.tif",summation, plugin="freeimage")
not using the freeimage plugin in not failing.
Siggi
On Wednesday, July 11, 2012 2:50:11 PM UTC+2, Zachary Pincus wrote:
I wonder if this has to do with the type-promotion behavior changes in a recent numpy version? What is the dtype of "summation" below?
two.dtype and summation.dtype return "int32" .dtype.type is returning
"<type 'numpy.int32'>" in both cases. I just tried it on a diffrent PC. Same problem on a Win32 XP 32bit system with EPD 7.2-2 Python 2.7.2
In summary. It is working on : Python 2.7.1 |EPD 7.0-2 (32-bit)| Win 7 32 Python 2.7.2 |EPD 7.2-2 (64-bit)| Mac OSX And not working on: Python 2.7.3 |EPD 7.3-1 (64-bit)| Win 7 64 Python 2.7.2 IEPD 7.2-2 (32-bit)| Win XP
On Jul 10, 2012, at 9:35 AM, Sigmund wrote:
Hey!
Whil writing the test code I found out that saving the array by itself
doesn't cause the error. Only after summing two arrays it fails.
import numpy as np import skimage.io as io io.use_plugin("freeimage", "imread") one = np.ones([2048,2048],dtype=np.int32) two = np.zeros([2048,2048],dtype=np.int32) summation = one + two io.imsave("test.tif",summation, plugin="freeimage")
not using the freeimage plugin in not failing.
Siggi
This is very curious. You have two arrays of identical dtype (that is, "two" and "summation"), and one can be saved via freeimage yet the other cannot? Is this correct?
Hopefully someone can try to verify this. Strange, too, that it would fail on XP but work on Win 7 32-bit. Perhaps that's a red herring and it has to do with the EPD version?
On Jul 12, 2012, at 8:41 AM, Sigmund wrote:
On Wednesday, July 11, 2012 2:50:11 PM UTC+2, Zachary Pincus wrote: I wonder if this has to do with the type-promotion behavior changes in a recent numpy version? What is the dtype of "summation" below?
two.dtype and summation.dtype return "int32" .dtype.type is returning "<type 'numpy.int32'>" in both cases. I just tried it on a diffrent PC. Same problem on a Win32 XP 32bit system with EPD 7.2-2 Python 2.7.2
In summary. It is working on : Python 2.7.1 |EPD 7.0-2 (32-bit)| Win 7 32 Python 2.7.2 |EPD 7.2-2 (64-bit)| Mac OSX And not working on: Python 2.7.3 |EPD 7.3-1 (64-bit)| Win 7 64 Python 2.7.2 IEPD 7.2-2 (32-bit)| Win XP
On Jul 10, 2012, at 9:35 AM, Sigmund wrote:
Hey!
Whil writing the test code I found out that saving the array by itself doesn't cause the error. Only after summing two arrays it fails.
import numpy as np import skimage.io as io io.use_plugin("freeimage", "imread") one = np.ones([2048,2048],dtype=np.int32) two = np.zeros([2048,2048],dtype=np.int32) summation = one + two io.imsave("test.tif",summation, plugin="freeimage")
not using the freeimage plugin in not failing.
Siggi
The freeimage plugin is comparing numpy's dtype.type (not dtype), which apparently does not work in this case:
import numpy as np one = np.ones([2048,2048],dtype=np.int32) two = np.zeros([2048,2048],dtype=np.int32) summation = one + two
assert repr(summation.dtype) == repr(one.dtype) assert summation.dtype == one.dtype assert hash(summation.dtype) == hash(one.dtype)
assert repr(summation.dtype.type) == repr(one.dtype.type) assert summation.dtype.type != one.dtype.type assert hash(summation.dtype.type) != hash(one.dtype.type)
I submitted a PR at https://github.com/scikits-image/scikits-image/pull/214
Christoph
On 7/12/2012 7:09 AM, Zachary Pincus wrote:
This is very curious. You have two arrays of identical dtype (that is, "two" and "summation"), and one can be saved via freeimage yet the other cannot? Is this correct?
Hopefully someone can try to verify this. Strange, too, that it would fail on XP but work on Win 7 32-bit. Perhaps that's a red herring and it has to do with the EPD version?
On Jul 12, 2012, at 8:41 AM, Sigmund wrote:
On Wednesday, July 11, 2012 2:50:11 PM UTC+2, Zachary Pincus wrote: I wonder if this has to do with the type-promotion behavior changes in a recent numpy version? What is the dtype of "summation" below?
two.dtype and summation.dtype return "int32" .dtype.type is returning "<type 'numpy.int32'>" in both cases. I just tried it on a diffrent PC. Same problem on a Win32 XP 32bit system with EPD 7.2-2 Python 2.7.2
In summary. It is working on : Python 2.7.1 |EPD 7.0-2 (32-bit)| Win 7 32 Python 2.7.2 |EPD 7.2-2 (64-bit)| Mac OSX And not working on: Python 2.7.3 |EPD 7.3-1 (64-bit)| Win 7 64 Python 2.7.2 IEPD 7.2-2 (32-bit)| Win XP
On Jul 10, 2012, at 9:35 AM, Sigmund wrote:
Hey!
Whil writing the test code I found out that saving the array by itself doesn't cause the error. Only after summing two arrays it fails.
import numpy as np import skimage.io as io io.use_plugin("freeimage", "imread") one = np.ones([2048,2048],dtype=np.int32) two = np.zeros([2048,2048],dtype=np.int32) summation = one + two io.imsave("test.tif",summation, plugin="freeimage")
not using the freeimage plugin in not failing.
Siggi