Save CroppedObjects with unique names throughout several images

Hi all,

This is with CellProfiler 3.1.8
I have multiple images, say 100, named 1, 2 3…
On each images, I have several, say 50, fluorescent nuclei, easily identified as PrimaryObjects with CellProfiler.
I use SaveCroppedObjects to get individual cropped images of all identified nuclei, named: IdentifyPrimaryObjects_1.tiff, IdentifyPrimaryObjects_2.tiff,…

This is fine when working on a single image. Unfortunately, when analyzing the second image, the cropped objects are saved in the same directory under the same names as those of the first image (IdentifyPrimaryObjects_1.tiff, IdentifyPrimaryObjects_2.tiff,…), and thus replace the CroppedObject images of the previous image…
Is there a way to add to the CroppedObject image names the name of the image they were extracted from? This way, they would all be saved with unique names, something like :
Image_1_IdentifyPrimaryObjects_1.tiff,
Image_1_IdentifyPrimaryObjects_2.tiff,
Image_2_IdentifyPrimaryObjects_1.tiff,
Image_2_IdentifyPrimaryObjects_2.tiff

Thanks for reading!
Philippe

Hi,
You can’t change the name of the images themselves, BUT you can put them in separate folders based on the input image name using the "Default Output Folder Sub-folder option- just capture the file’s name in the Metadata module, and then you can use that as a subfolder in SaveCroppedObjects.

Thank you for this alternative solution. Not as straightforward as what I was hoping for, but great nevertheless since it is a way to get what I want.
:slightly_smiling_face:

Hi,

Would you mind outlining how to do this with the stable release of CellProfiler? I don’t see where to register the metadata extraction as an option when saving to subfolder.

Hi @alexanderchang1,

Welcome to the image.sc forum! In order to insert a Metadata tag, you can right-click in the text entry box and a menu should appear with your metadata options. I hope that works for you and let us know if it doesn’t!

Best,
Pearl

Hi,

Thank you for your reply. I tried that but unfortunately, the folders are all coming up as “None”. Please see screenshots below

Hi,

Just following up on this, apologies for the rush, I’m on a deadline to get these images cropped so I can do subsequent analysis. Do you have any insight why the export folder is called “None”?

My guess is that there’s an error with your Metadata extraction - that somehow the extracted value is None, which is why that gets saved. Others may have different ideas based on their experience.

If you can share an example pipeline and image set, that would make it easier to diagnose the problem and come up with a solution.

Good luck!

Hi,

Please find attached an example pipeline and example image set.
GroupedSegmentation - Masks.cppipe (9.0 KB)

1997S_2_20_2021_1.tif_DAPI.tif (512.2 KB)
1997S_2_20_2021_1.tif_CYT.tif (512.2 KB)

Thanks @alexanderchang1,

I think I can see the reason you were getting this error is because the Filename and Filelocation tags are different for the two images that make up your image set. Since CellProfiler doesn’t know which is the correct one to associate with that image set, it sets the tag to None.

Using your pipeline, I updated the metadata for Filename extraction to: ^(?P<Filename>.*).tif_[A-Z]*.tif. This matches the Filename tag to only the first part of your image name (the part that is the same for both images in your image set). When I then run SaveCroppedObjects using the Filename tag, the result saves in the expected location:

Sub-folder:

File system location:
Screen Shot 2021-06-14 at 11.28.56 AM

I hope this helps!
Cheers,
Pearl

Hi Pearl,

Thank you, I think that fixed it. Just to clarify, what do you mean that my metadata regex couldn’t associate? With my previous line, I could get the filename in the table, I still don’t quite understand how the backend of the software couldn’t connect the result in the table with the folder naming protocol.

The issue was, you were telling the software to use Filename to make the folder, but each image set had 2 files and thus 2 different Filenames - whatever_DAPI.tif and whatever_CYT.tif . Only metadata that is common to every image in the set (which Filename now is in @pearl-ryder 's new suggested string) can be used to set folder location.

Ah, that makes sense, thank you both so much!