SaveImages on stacks bug

Hi all,
Basically, I’m trying to open a two-channel TIF, crop it down according to an identified object (nuclei), and save it again as a two-channel TIF. The ways that I’ve tried doing this so far have been

1)Take the individual channel images from ColorToGray, crop/mask (I’ve tried both, no effect, nor with trying removing/keeping empty columns within the crop module) them both down using the same object (Nuclei), then using the GrayToColor module to recombine those cropped/masked images, followed by SaveImages to save as a 16 bit TIF/TIFF*.
2)Take the original loaded image, crop it down (masking won’t work since it’s not grayscale) using Nuclei, then using SaveImages to save as a 16 bit TIF/TIFF*.

Both give the following error message.

Traceback (most recent call last):
File “cellprofiler\pipeline.pyc”, line 309, in run
File “cellprofiler\modules\saveimages.pyc”, line 407, in run
File “cellprofiler\modules\saveimages.pyc”, line 448, in run_image
File “cellprofiler\modules\saveimages.pyc”, line 752, in save_image
File “cellprofiler\modules\saveimages.pyc”, line 615, in save_image_with_bioformats
TypeError: exceptions must be classes or instances, not str

This seems to be a stack-specific problem, since doing method 1 but selecting RGB instead of stack as the output in GrayToColor works just fine. Unfortunately, I would like the output as a stack- any way to make this happen? Thanks.

*=(As an aside, if I try to use an 8 bit TIF instead, I get the error message:
Traceback (most recent call last):
File “cellprofiler\pipeline.pyc”, line 309, in run
File “cellprofiler\modules\saveimages.pyc”, line 407, in run
File “cellprofiler\modules\saveimages.pyc”, line 448, in run_image
File “cellprofiler\modules\saveimages.pyc”, line 826, in save_image
File “Image.pyc”, line 1902, in fromarray
File “Image.pyc”, line 1858, in frombuffer
File “Image.pyc”, line 1797, in fromstring
File “Image.pyc”, line 594, in fromstring
ValueError: not enough image data)

Could you post the offending image and the pipeline that you are using?


Sure- it’s part of a much bigger pipeline but here’s the relevant sub-part (up until where it fails).

pipelineforcellprofiler.cp (9.31 KB)

Any ideas on a workaround for this? Alternately, if I export the two channels as separate images (ie output CroppedNuclei_#Red and Cropped Nuclei#_Green), is there a way I can construct a pipeline to load all the corresponding images at the same time (ie first pass load CroppedNuclei_1_Red and CroppedNuclei_1_Green, then next pass CroppedNuclei_2_Red and Green, etc?)


You are correct in that SaveImages currently does not handle stacks; I’ve added this as a future feature improvement.

To do this, you could use LoadImages with regular expressions as the file selection method. The text you would have in common for the two images would then be (

  • CroppedNuclei_\d*_Red
  • CroppedNuclei_\d*_Green

where ‘\d*’ indicates a match for zero or more digits.


Thank you so much, that’s exactly what I needed to know!

We have recently corrected these stack-specific issues in our source code. The fix will be included in the next release, but if you’re daring, you can try it out with our latest public build from source code here.

The trunk build is not as heavily vetted as our releases, so you should take that into account; please note the caveats mentioned on the page linked.