Slicing based on Metadata info




Kudos to the Devs for making such an impressive progress with CellProfiler, particularly going 3D; many thanks!

Sorry if the answer to the following already appeared before:
How do I slice my dataset before running the analysis?

To be more specific:
I have a CZI (Zeiss format) of a time-lapse (about 700 frames) and would like to analyse only frames #200-#300 .
Other use cases:
If one needs only every nth (e.g. 2nd) time frame, or z-slice and so on.

I guess one could extract all frames, saving them using some meaningful name and then use regex to filter; Is there a way to achieve data slicing directly in CellProfiler (given a single file with many frames), without having to first extract them? I could not apply regex in the NamesAndTypes module module



I have the same type of issue (as posted here: Use of subset of images within a file).
I agree that such feature would be very, very useful!!!

Looking forward any advice on how to do this within CellProfiler (if possible! :wink: )





Unfortunately there’s no way to do this in CellProfiler natively at this time- the only way I can think of to do it would be to either a) as you said, extract out as files only the frames that you want or b) create a CSV that contains the file names, frame numbers, and a column that determines whether it should be processed (ie one that’s either “Yes” or “No”) and pass that into Metadata using the “Import CSV” option. Sorry!


@bcimini Thanks for clarifying this, and for your suggestions.
Would you know whether the suggested CSV (before adding the extra column) can be created using Cellprofiler?
I am asking as I expect this to guarantee the CSV to be importable by CellProfiler (possibly reducing bugs).



You could export the CSV from CellProfiler after making your image sets (aka setting up everything nicely in Metadata and NamesAndTypes) using the “Export->Image set listing” option. You could then either add the extra column as I described above OR delete all but the rows that you care about and use the “LoadData” module to load images directly from the CSV.


Thank you, that’s helpful!

I have not been able to load the images, not even from the CSV as exported by CellProfiler (without modifying it).
Could I kindly ask you for the instructions how to load images from CSV?

For reference (I), here’s a python code (using pandas) to modify the resulting CSV (exported following bcimini’s reply ):

import pandas as pd

csv_name = 'my_metadata.csv'
metadata_df = pd.read_csv(csv_name)
## append an extra column of 'Yes's, including all
metadata_df = metadata_df.assign(to_consider='Yes', )

## to achieve what I asked for, here we flip all to `No`s and switch only a slice to `Yes`s
metadata_df.to_consider = 'No'
metadata_df.to_consider.loc[200:300] = 'Yes'

## save a renamed file 
metadata_df.to_csv(csv_name.replace('.csv', '_filtered.csv'), index=False)

For reference (II), detected a minor CellProfiler UI bug; opened an issue .