repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_documentation_string
stringlengths
1
47.2k
func_code_url
stringlengths
85
339
signetlabdei/sem
sem/manager.py
CampaignManager.check_repo_ok
def check_repo_ok(self): """ Make sure that the ns-3 repository's HEAD commit is the same as the one saved in the campaign database, and that the ns-3 repository is clean (i.e., no untracked or modified files exist). """ from git import Repo, exc # Check that git ...
python
def check_repo_ok(self): """ Make sure that the ns-3 repository's HEAD commit is the same as the one saved in the campaign database, and that the ns-3 repository is clean (i.e., no untracked or modified files exist). """ from git import Repo, exc # Check that git ...
Make sure that the ns-3 repository's HEAD commit is the same as the one saved in the campaign database, and that the ns-3 repository is clean (i.e., no untracked or modified files exist).
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/manager.py#L616-L642
signetlabdei/sem
sem/cli.py
run
def run(ns_3_path, results_dir, script, no_optimization, parameters, max_processes): """ Run multiple simulations. """ sem.parallelrunner.MAX_PARALLEL_PROCESSES = max_processes # Create a campaign campaign = sem.CampaignManager.new(ns_3_path, scri...
python
def run(ns_3_path, results_dir, script, no_optimization, parameters, max_processes): """ Run multiple simulations. """ sem.parallelrunner.MAX_PARALLEL_PROCESSES = max_processes # Create a campaign campaign = sem.CampaignManager.new(ns_3_path, scri...
Run multiple simulations.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/cli.py#L55-L94
signetlabdei/sem
sem/cli.py
view
def view(results_dir, result_id, hide_simulation_output, parameters, no_pager): """ View results of simulations. """ campaign = sem.CampaignManager.load(results_dir) # Pick the most appropriate function based on the level of detail we want if hide_simulation_output: get_results_functio...
python
def view(results_dir, result_id, hide_simulation_output, parameters, no_pager): """ View results of simulations. """ campaign = sem.CampaignManager.load(results_dir) # Pick the most appropriate function based on the level of detail we want if hide_simulation_output: get_results_functio...
View results of simulations.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/cli.py#L128-L168
signetlabdei/sem
sem/cli.py
command
def command(results_dir, result_id): """ Print the command that needs to be used to reproduce a result. """ campaign = sem.CampaignManager.load(results_dir) result = campaign.db.get_results(result_id=result_id)[0] click.echo("Simulation command:") click.echo(sem.utils.get_command_from_resu...
python
def command(results_dir, result_id): """ Print the command that needs to be used to reproduce a result. """ campaign = sem.CampaignManager.load(results_dir) result = campaign.db.get_results(result_id=result_id)[0] click.echo("Simulation command:") click.echo(sem.utils.get_command_from_resu...
Print the command that needs to be used to reproduce a result.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/cli.py#L181-L195
signetlabdei/sem
sem/cli.py
export
def export(results_dir, filename, do_not_try_parsing, parameters): """ Export results to file. An extension in filename is required to deduce the file type. If no extension is specified, a directory tree export will be used. Note that this command automatically tries to parse the simulation output....
python
def export(results_dir, filename, do_not_try_parsing, parameters): """ Export results to file. An extension in filename is required to deduce the file type. If no extension is specified, a directory tree export will be used. Note that this command automatically tries to parse the simulation output....
Export results to file. An extension in filename is required to deduce the file type. If no extension is specified, a directory tree export will be used. Note that this command automatically tries to parse the simulation output. Supported extensions: .mat (Matlab file), .npy (Numpy file), ...
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/cli.py#L220-L268
signetlabdei/sem
sem/cli.py
merge
def merge(move, output_dir, sources): """ Merge multiple results folder into one, by copying the results over to a new folder. For a faster operation (which on the other hand destroys the campaign data if interrupted), the move option can be used to directly move results to the new folder. """ ...
python
def merge(move, output_dir, sources): """ Merge multiple results folder into one, by copying the results over to a new folder. For a faster operation (which on the other hand destroys the campaign data if interrupted), the move option can be used to directly move results to the new folder. """ ...
Merge multiple results folder into one, by copying the results over to a new folder. For a faster operation (which on the other hand destroys the campaign data if interrupted), the move option can be used to directly move results to the new folder.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/cli.py#L286-L335
signetlabdei/sem
sem/cli.py
get_params_and_defaults
def get_params_and_defaults(param_list, db): """ Deduce [parameter, default] pairs from simulations available in the db. Args: param_list (list): List of parameters to query for. db (DatabaseManager): Database where to query for defaults. """ return [[p, d] for p, d in db.get_all_values...
python
def get_params_and_defaults(param_list, db): """ Deduce [parameter, default] pairs from simulations available in the db. Args: param_list (list): List of parameters to query for. db (DatabaseManager): Database where to query for defaults. """ return [[p, d] for p, d in db.get_all_values...
Deduce [parameter, default] pairs from simulations available in the db. Args: param_list (list): List of parameters to query for. db (DatabaseManager): Database where to query for defaults.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/cli.py#L338-L346
signetlabdei/sem
sem/cli.py
query_parameters
def query_parameters(param_list, defaults=None): """ Asks the user for parameters. If available, proposes some defaults. Args: param_list (list): List of parameters to ask the user for values. defaults (list): A list of proposed defaults. It must be a list of the same length as ...
python
def query_parameters(param_list, defaults=None): """ Asks the user for parameters. If available, proposes some defaults. Args: param_list (list): List of parameters to ask the user for values. defaults (list): A list of proposed defaults. It must be a list of the same length as ...
Asks the user for parameters. If available, proposes some defaults. Args: param_list (list): List of parameters to ask the user for values. defaults (list): A list of proposed defaults. It must be a list of the same length as param_list. A value of None in one element of the ...
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/cli.py#L349-L367
signetlabdei/sem
sem/cli.py
import_parameters_from_file
def import_parameters_from_file(parameters_file): """ Try importing a parameter dictionary from file. We expect values in parameters_file to be defined as follows: param1: value1 param2: [value2, value3] """ params = {} with open(parameters_file, 'r') as f: matches = re...
python
def import_parameters_from_file(parameters_file): """ Try importing a parameter dictionary from file. We expect values in parameters_file to be defined as follows: param1: value1 param2: [value2, value3] """ params = {} with open(parameters_file, 'r') as f: matches = re...
Try importing a parameter dictionary from file. We expect values in parameters_file to be defined as follows: param1: value1 param2: [value2, value3]
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/cli.py#L370-L386
signetlabdei/sem
sem/parallelrunner.py
ParallelRunner.run_simulations
def run_simulations(self, parameter_list, data_folder): """ This function runs multiple simulations in parallel. Args: parameter_list (list): list of parameter combinations to simulate. data_folder (str): folder in which to create output folders. """ self...
python
def run_simulations(self, parameter_list, data_folder): """ This function runs multiple simulations in parallel. Args: parameter_list (list): list of parameter combinations to simulate. data_folder (str): folder in which to create output folders. """ self...
This function runs multiple simulations in parallel. Args: parameter_list (list): list of parameter combinations to simulate. data_folder (str): folder in which to create output folders.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/parallelrunner.py#L12-L24
signetlabdei/sem
sem/parallelrunner.py
ParallelRunner.launch_simulation
def launch_simulation(self, parameter): """ Launch a single simulation, using SimulationRunner's facilities. This function is used by ParallelRunner's run_simulations to map simulation running over the parameter list. Args: parameter (dict): the parameter combinatio...
python
def launch_simulation(self, parameter): """ Launch a single simulation, using SimulationRunner's facilities. This function is used by ParallelRunner's run_simulations to map simulation running over the parameter list. Args: parameter (dict): the parameter combinatio...
Launch a single simulation, using SimulationRunner's facilities. This function is used by ParallelRunner's run_simulations to map simulation running over the parameter list. Args: parameter (dict): the parameter combination to simulate.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/parallelrunner.py#L26-L37
why2pac/dp-tornado
dp_tornado/helper/serialization/json.py
JsonHelper.stringify
def stringify(self, obj, beautify=False, raise_exception=False): """Alias of helper.string.serialization.json.stringify""" return self.helper.string.serialization.json.stringify( obj=obj, beautify=beautify, raise_exception=raise_exception)
python
def stringify(self, obj, beautify=False, raise_exception=False): """Alias of helper.string.serialization.json.stringify""" return self.helper.string.serialization.json.stringify( obj=obj, beautify=beautify, raise_exception=raise_exception)
Alias of helper.string.serialization.json.stringify
https://github.com/why2pac/dp-tornado/blob/a5948f5693f6ee2d9bab31f611fedc074e1caa96/dp_tornado/helper/serialization/json.py#L9-L15
why2pac/dp-tornado
dp_tornado/helper/serialization/json.py
JsonHelper.parse
def parse(self, text, encoding='utf8', raise_exception=False): """Alias of helper.string.serialization.json.parse""" return self.helper.string.serialization.json.parse( text=text, encoding=encoding, raise_exception=raise_exception)
python
def parse(self, text, encoding='utf8', raise_exception=False): """Alias of helper.string.serialization.json.parse""" return self.helper.string.serialization.json.parse( text=text, encoding=encoding, raise_exception=raise_exception)
Alias of helper.string.serialization.json.parse
https://github.com/why2pac/dp-tornado/blob/a5948f5693f6ee2d9bab31f611fedc074e1caa96/dp_tornado/helper/serialization/json.py#L17-L23
signetlabdei/sem
sem/database.py
DatabaseManager.new
def new(cls, script, commit, params, campaign_dir, overwrite=False): """ Initialize a new class instance with a set configuration and filename. The created database has the same name of the campaign directory. Args: script (str): the ns-3 name of the script that will be use...
python
def new(cls, script, commit, params, campaign_dir, overwrite=False): """ Initialize a new class instance with a set configuration and filename. The created database has the same name of the campaign directory. Args: script (str): the ns-3 name of the script that will be use...
Initialize a new class instance with a set configuration and filename. The created database has the same name of the campaign directory. Args: script (str): the ns-3 name of the script that will be used in this campaign; commit (str): the commit of the ns-3 inst...
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/database.py#L39-L95
signetlabdei/sem
sem/database.py
DatabaseManager.load
def load(cls, campaign_dir): """ Initialize from an existing database. It is assumed that the database json file has the same name as its containing folder. Args: campaign_dir (str): The path to the campaign directory. """ # We only accept absolute ...
python
def load(cls, campaign_dir): """ Initialize from an existing database. It is assumed that the database json file has the same name as its containing folder. Args: campaign_dir (str): The path to the campaign directory. """ # We only accept absolute ...
Initialize from an existing database. It is assumed that the database json file has the same name as its containing folder. Args: campaign_dir (str): The path to the campaign directory.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/database.py#L98-L135
signetlabdei/sem
sem/database.py
DatabaseManager.get_next_rngruns
def get_next_rngruns(self): """ Yield the next RngRun values that can be used in this campaign. """ available_runs = [result['params']['RngRun'] for result in self.get_results()] yield from DatabaseManager.get_next_values(available_runs)
python
def get_next_rngruns(self): """ Yield the next RngRun values that can be used in this campaign. """ available_runs = [result['params']['RngRun'] for result in self.get_results()] yield from DatabaseManager.get_next_values(available_runs)
Yield the next RngRun values that can be used in this campaign.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/database.py#L180-L186
signetlabdei/sem
sem/database.py
DatabaseManager.insert_result
def insert_result(self, result): """ Insert a new result in the database. This function also verifies that the result dictionaries saved in the database have the following structure (with {'a': 1} representing a dictionary, 'a' a key and 1 its value):: { ...
python
def insert_result(self, result): """ Insert a new result in the database. This function also verifies that the result dictionaries saved in the database have the following structure (with {'a': 1} representing a dictionary, 'a' a key and 1 its value):: { ...
Insert a new result in the database. This function also verifies that the result dictionaries saved in the database have the following structure (with {'a': 1} representing a dictionary, 'a' a key and 1 its value):: { 'params': { 'param1'...
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/database.py#L188-L231
signetlabdei/sem
sem/database.py
DatabaseManager.get_results
def get_results(self, params=None, result_id=None): """ Return all the results available from the database that fulfill some parameter combinations. If params is None (or not specified), return all results. If params is specified, it must be a dictionary specifying the result ...
python
def get_results(self, params=None, result_id=None): """ Return all the results available from the database that fulfill some parameter combinations. If params is None (or not specified), return all results. If params is specified, it must be a dictionary specifying the result ...
Return all the results available from the database that fulfill some parameter combinations. If params is None (or not specified), return all results. If params is specified, it must be a dictionary specifying the result values we are interested in, with multiple values specified as li...
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/database.py#L233-L304
signetlabdei/sem
sem/database.py
DatabaseManager.get_result_files
def get_result_files(self, result): """ Return a dictionary containing filename: filepath values for each output file associated with an id. Result can be either a result dictionary (e.g., obtained with the get_results() method) or a result id. """ if isinstance(...
python
def get_result_files(self, result): """ Return a dictionary containing filename: filepath values for each output file associated with an id. Result can be either a result dictionary (e.g., obtained with the get_results() method) or a result id. """ if isinstance(...
Return a dictionary containing filename: filepath values for each output file associated with an id. Result can be either a result dictionary (e.g., obtained with the get_results() method) or a result id.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/database.py#L306-L327
signetlabdei/sem
sem/database.py
DatabaseManager.get_complete_results
def get_complete_results(self, params=None, result_id=None): """ Return available results, analogously to what get_results does, but also read the corresponding output files for each result, and incorporate them in the result dictionary under the output key, as a dictionary of fi...
python
def get_complete_results(self, params=None, result_id=None): """ Return available results, analogously to what get_results does, but also read the corresponding output files for each result, and incorporate them in the result dictionary under the output key, as a dictionary of fi...
Return available results, analogously to what get_results does, but also read the corresponding output files for each result, and incorporate them in the result dictionary under the output key, as a dictionary of filename: file_contents. Args: params (dict): parameter specific...
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/database.py#L329-L377
signetlabdei/sem
sem/database.py
DatabaseManager.wipe_results
def wipe_results(self): """ Remove all results from the database. This also removes all output files, and cannot be undone. """ # Clean results table self.db.purge_table('results') # Get rid of contents of data dir map(shutil.rmtree, glob.glob(os.path.jo...
python
def wipe_results(self): """ Remove all results from the database. This also removes all output files, and cannot be undone. """ # Clean results table self.db.purge_table('results') # Get rid of contents of data dir map(shutil.rmtree, glob.glob(os.path.jo...
Remove all results from the database. This also removes all output files, and cannot be undone.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/database.py#L379-L389
signetlabdei/sem
sem/database.py
DatabaseManager.have_same_structure
def have_same_structure(d1, d2): """ Given two dictionaries (possibly with other nested dictionaries as values), this function checks whether they have the same key structure. >>> from sem import DatabaseManager >>> d1 = {'a': 1, 'b': 2} >>> d2 = {'a': [], 'b': 3} ...
python
def have_same_structure(d1, d2): """ Given two dictionaries (possibly with other nested dictionaries as values), this function checks whether they have the same key structure. >>> from sem import DatabaseManager >>> d1 = {'a': 1, 'b': 2} >>> d2 = {'a': [], 'b': 3} ...
Given two dictionaries (possibly with other nested dictionaries as values), this function checks whether they have the same key structure. >>> from sem import DatabaseManager >>> d1 = {'a': 1, 'b': 2} >>> d2 = {'a': [], 'b': 3} >>> d3 = {'a': 4, 'c': 5} >>> DatabaseManag...
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/database.py#L417-L455
signetlabdei/sem
sem/database.py
DatabaseManager.get_all_values_of_all_params
def get_all_values_of_all_params(self): """ Return a dictionary containing all values that are taken by all available parameters. Always returns the parameter list in alphabetical order. """ values = collections.OrderedDict([[p, []] for p in ...
python
def get_all_values_of_all_params(self): """ Return a dictionary containing all values that are taken by all available parameters. Always returns the parameter list in alphabetical order. """ values = collections.OrderedDict([[p, []] for p in ...
Return a dictionary containing all values that are taken by all available parameters. Always returns the parameter list in alphabetical order.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/database.py#L457-L480
why2pac/dp-tornado
dp_tornado/helper/serialization/__init__.py
SerializationHelper.serialize
def serialize(self, obj, method='json', beautify=False, raise_exception=False): """Alias of helper.string.serialization.serialize""" return self.helper.string.serialization.serialize( obj=obj, method=method, beautify=beautify, raise_exception=raise_exception)
python
def serialize(self, obj, method='json', beautify=False, raise_exception=False): """Alias of helper.string.serialization.serialize""" return self.helper.string.serialization.serialize( obj=obj, method=method, beautify=beautify, raise_exception=raise_exception)
Alias of helper.string.serialization.serialize
https://github.com/why2pac/dp-tornado/blob/a5948f5693f6ee2d9bab31f611fedc074e1caa96/dp_tornado/helper/serialization/__init__.py#L9-L13
why2pac/dp-tornado
dp_tornado/helper/serialization/__init__.py
SerializationHelper.deserialize
def deserialize(self, text, method='json', encoding='utf8', raise_exception=False): """Alias of helper.string.serialization.deserialize""" return self.helper.string.serialization.deserialize( text, method=method, encoding=encoding, raise_exception=raise_exception)
python
def deserialize(self, text, method='json', encoding='utf8', raise_exception=False): """Alias of helper.string.serialization.deserialize""" return self.helper.string.serialization.deserialize( text, method=method, encoding=encoding, raise_exception=raise_exception)
Alias of helper.string.serialization.deserialize
https://github.com/why2pac/dp-tornado/blob/a5948f5693f6ee2d9bab31f611fedc074e1caa96/dp_tornado/helper/serialization/__init__.py#L15-L19
signetlabdei/sem
sem/gridrunner.py
GridRunner.run_simulations
def run_simulations(self, parameter_list, data_folder): """ This function runs multiple simulations in parallel. """ # Open up a session s = drmaa.Session() s.initialize() # Create a job template for each parameter combination jobs = {} for param...
python
def run_simulations(self, parameter_list, data_folder): """ This function runs multiple simulations in parallel. """ # Open up a session s = drmaa.Session() s.initialize() # Create a job template for each parameter combination jobs = {} for param...
This function runs multiple simulations in parallel.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/gridrunner.py#L24-L118
signetlabdei/sem
sem/gridrunner.py
GridRunner.get_available_parameters
def get_available_parameters(self): """ Return a list of the parameters made available by the script. """ # At the moment, we rely on regex to extract the list of available # parameters. A tighter integration with waf would allow for a more # natural extraction of the in...
python
def get_available_parameters(self): """ Return a list of the parameters made available by the script. """ # At the moment, we rely on regex to extract the list of available # parameters. A tighter integration with waf would allow for a more # natural extraction of the in...
Return a list of the parameters made available by the script.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/gridrunner.py#L141-L163
signetlabdei/sem
sem/gridrunner.py
GridRunner.run_program
def run_program(self, command, working_directory=os.getcwd(), environment=None, cleanup_files=True, native_spec="-l cputype=intel"): """ Run a program through the grid, capturing the standard output. """ try: s = drmaa.Session() ...
python
def run_program(self, command, working_directory=os.getcwd(), environment=None, cleanup_files=True, native_spec="-l cputype=intel"): """ Run a program through the grid, capturing the standard output. """ try: s = drmaa.Session() ...
Run a program through the grid, capturing the standard output.
https://github.com/signetlabdei/sem/blob/5077dd7a6d15644a18790bb6fde320e905f0fef0/sem/gridrunner.py#L165-L208
CellProfiler/centrosome
centrosome/cpmorphology.py
fill_labeled_holes
def fill_labeled_holes(labels, mask=None, size_fn = None): '''Fill all background pixels that are holes inside the foreground A pixel is a hole inside a foreground object if * there is no path from the pixel to the edge AND * there is no path from the pixel to any other non-hole pixel ...
python
def fill_labeled_holes(labels, mask=None, size_fn = None): '''Fill all background pixels that are holes inside the foreground A pixel is a hole inside a foreground object if * there is no path from the pixel to the edge AND * there is no path from the pixel to any other non-hole pixel ...
Fill all background pixels that are holes inside the foreground A pixel is a hole inside a foreground object if * there is no path from the pixel to the edge AND * there is no path from the pixel to any other non-hole pixel AND * there is no path from the pixel to two similarly-...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L33-L149
CellProfiler/centrosome
centrosome/cpmorphology.py
adjacent
def adjacent(labels): '''Return a binary mask of all pixels which are adjacent to a pixel of a different label. ''' high = labels.max()+1 if high > np.iinfo(labels.dtype).max: labels = labels.astype(np.int) image_with_high_background = labels.copy() image_with_high_backgr...
python
def adjacent(labels): '''Return a binary mask of all pixels which are adjacent to a pixel of a different label. ''' high = labels.max()+1 if high > np.iinfo(labels.dtype).max: labels = labels.astype(np.int) image_with_high_background = labels.copy() image_with_high_backgr...
Return a binary mask of all pixels which are adjacent to a pixel of a different label.
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L151-L169
CellProfiler/centrosome
centrosome/cpmorphology.py
binary_thin
def binary_thin(image, strel1, strel2): """Morphologically thin an image strel1 - the required values of the pixels in order to survive strel2 - at each pixel, the complement of strel1 if we care about the value """ hit_or_miss = scind.binary_hit_or_miss(image, strel1, strel2) return np.logical_...
python
def binary_thin(image, strel1, strel2): """Morphologically thin an image strel1 - the required values of the pixels in order to survive strel2 - at each pixel, the complement of strel1 if we care about the value """ hit_or_miss = scind.binary_hit_or_miss(image, strel1, strel2) return np.logical_...
Morphologically thin an image strel1 - the required values of the pixels in order to survive strel2 - at each pixel, the complement of strel1 if we care about the value
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L171-L177
CellProfiler/centrosome
centrosome/cpmorphology.py
binary_shrink_old
def binary_shrink_old(image, iterations=-1): """Shrink an image by repeatedly removing pixels which have partners above, to the left, to the right and below until the image doesn't change image - binary image to be manipulated iterations - # of times to shrink, -1 to shrink until idempo...
python
def binary_shrink_old(image, iterations=-1): """Shrink an image by repeatedly removing pixels which have partners above, to the left, to the right and below until the image doesn't change image - binary image to be manipulated iterations - # of times to shrink, -1 to shrink until idempo...
Shrink an image by repeatedly removing pixels which have partners above, to the left, to the right and below until the image doesn't change image - binary image to be manipulated iterations - # of times to shrink, -1 to shrink until idempotent There are horizontal/vertical th...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L181-L317
CellProfiler/centrosome
centrosome/cpmorphology.py
binary_shrink
def binary_shrink(image, iterations=-1): """Shrink an image by repeatedly removing pixels which have partners above, to the left, to the right and below until the image doesn't change image - binary image to be manipulated iterations - # of times to shrink, -1 to shrink until idempotent...
python
def binary_shrink(image, iterations=-1): """Shrink an image by repeatedly removing pixels which have partners above, to the left, to the right and below until the image doesn't change image - binary image to be manipulated iterations - # of times to shrink, -1 to shrink until idempotent...
Shrink an image by repeatedly removing pixels which have partners above, to the left, to the right and below until the image doesn't change image - binary image to be manipulated iterations - # of times to shrink, -1 to shrink until idempotent There are horizontal/vertical th...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L324-L430
CellProfiler/centrosome
centrosome/cpmorphology.py
strel_disk
def strel_disk(radius): """Create a disk structuring element for morphological operations radius - radius of the disk """ iradius = int(radius) x,y = np.mgrid[-iradius:iradius+1,-iradius:iradius+1] radius2 = radius * radius strel = np.zeros(x.shape) strel[x*x+y*y <= radius2] =...
python
def strel_disk(radius): """Create a disk structuring element for morphological operations radius - radius of the disk """ iradius = int(radius) x,y = np.mgrid[-iradius:iradius+1,-iradius:iradius+1] radius2 = radius * radius strel = np.zeros(x.shape) strel[x*x+y*y <= radius2] =...
Create a disk structuring element for morphological operations radius - radius of the disk
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L432-L442
CellProfiler/centrosome
centrosome/cpmorphology.py
strel_diamond
def strel_diamond(radius): """Create a diamond structuring element for morphological operations radius - the offset of the corners of the diamond from the origin rounded down (e.g. r=2: (0, 2), (2, 0), (0, -2), (-2, 0)) returns a two-dimensional binary array """ iradi...
python
def strel_diamond(radius): """Create a diamond structuring element for morphological operations radius - the offset of the corners of the diamond from the origin rounded down (e.g. r=2: (0, 2), (2, 0), (0, -2), (-2, 0)) returns a two-dimensional binary array """ iradi...
Create a diamond structuring element for morphological operations radius - the offset of the corners of the diamond from the origin rounded down (e.g. r=2: (0, 2), (2, 0), (0, -2), (-2, 0)) returns a two-dimensional binary array
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L444-L457
CellProfiler/centrosome
centrosome/cpmorphology.py
strel_line
def strel_line(length, angle): """Create a line structuring element for morphological operations length - distance between first and last pixels of the line, rounded down angle - angle from the horizontal, counter-clockwise in degrees. Note: uses draw_line's Bresenham algorithm to select ...
python
def strel_line(length, angle): """Create a line structuring element for morphological operations length - distance between first and last pixels of the line, rounded down angle - angle from the horizontal, counter-clockwise in degrees. Note: uses draw_line's Bresenham algorithm to select ...
Create a line structuring element for morphological operations length - distance between first and last pixels of the line, rounded down angle - angle from the horizontal, counter-clockwise in degrees. Note: uses draw_line's Bresenham algorithm to select points.
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L459-L483
CellProfiler/centrosome
centrosome/cpmorphology.py
strel_octagon
def strel_octagon(radius): """Create an octagonal structuring element for morphological operations radius - the distance from the origin to each edge of the octagon """ # # Inscribe a diamond in a square to get an octagon. # iradius = int(radius) i, j = np.mgrid[-iradius:(iradius + ...
python
def strel_octagon(radius): """Create an octagonal structuring element for morphological operations radius - the distance from the origin to each edge of the octagon """ # # Inscribe a diamond in a square to get an octagon. # iradius = int(radius) i, j = np.mgrid[-iradius:(iradius + ...
Create an octagonal structuring element for morphological operations radius - the distance from the origin to each edge of the octagon
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L485-L506
CellProfiler/centrosome
centrosome/cpmorphology.py
strel_pair
def strel_pair(x, y): """Create a structing element composed of the origin and another pixel x, y - x and y offsets of the other pixel returns a structuring element """ x_center = int(np.abs(x)) y_center = int(np.abs(y)) result = np.zeros((y_center * 2 + 1, x_center * 2 + 1), bool...
python
def strel_pair(x, y): """Create a structing element composed of the origin and another pixel x, y - x and y offsets of the other pixel returns a structuring element """ x_center = int(np.abs(x)) y_center = int(np.abs(y)) result = np.zeros((y_center * 2 + 1, x_center * 2 + 1), bool...
Create a structing element composed of the origin and another pixel x, y - x and y offsets of the other pixel returns a structuring element
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L508-L521
CellProfiler/centrosome
centrosome/cpmorphology.py
strel_periodicline
def strel_periodicline(xoff, yoff, n): """Create a structuring element composed of a line of evenly-spaced points xoff, yoff - the line goes through the origin and this point n - the line is composed of the origin and n points on either side of the origin for a total of 2*n + 1 points ...
python
def strel_periodicline(xoff, yoff, n): """Create a structuring element composed of a line of evenly-spaced points xoff, yoff - the line goes through the origin and this point n - the line is composed of the origin and n points on either side of the origin for a total of 2*n + 1 points ...
Create a structuring element composed of a line of evenly-spaced points xoff, yoff - the line goes through the origin and this point n - the line is composed of the origin and n points on either side of the origin for a total of 2*n + 1 points The structuring element is composed of...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L523-L540
CellProfiler/centrosome
centrosome/cpmorphology.py
strel_rectangle
def strel_rectangle(width, height): """Create a rectangular structuring element width - the width of the structuring element (in the j direction). The width will be rounded down to the nearest multiple of 2*n+1 height = the height of the structuring element (in the i direction)...
python
def strel_rectangle(width, height): """Create a rectangular structuring element width - the width of the structuring element (in the j direction). The width will be rounded down to the nearest multiple of 2*n+1 height = the height of the structuring element (in the i direction)...
Create a rectangular structuring element width - the width of the structuring element (in the j direction). The width will be rounded down to the nearest multiple of 2*n+1 height = the height of the structuring element (in the i direction). The height will be rounded do...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L542-L551
CellProfiler/centrosome
centrosome/cpmorphology.py
cpmaximum
def cpmaximum(image, structure=np.ones((3,3),dtype=bool),offset=None): """Find the local maximum at each point in the image, using the given structuring element image - a 2-d array of doubles structure - a boolean structuring element indicating which local elements should be sampled ...
python
def cpmaximum(image, structure=np.ones((3,3),dtype=bool),offset=None): """Find the local maximum at each point in the image, using the given structuring element image - a 2-d array of doubles structure - a boolean structuring element indicating which local elements should be sampled ...
Find the local maximum at each point in the image, using the given structuring element image - a 2-d array of doubles structure - a boolean structuring element indicating which local elements should be sampled offset - the offset to the center of the structuring element
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L561-L574
CellProfiler/centrosome
centrosome/cpmorphology.py
relabel
def relabel(image): """Given a labeled image, relabel each of the objects consecutively image - a labeled 2-d integer array returns - (labeled image, object count) """ # # Build a label table that converts an old label # into # labels using the new numbering scheme # unique_lab...
python
def relabel(image): """Given a labeled image, relabel each of the objects consecutively image - a labeled 2-d integer array returns - (labeled image, object count) """ # # Build a label table that converts an old label # into # labels using the new numbering scheme # unique_lab...
Given a labeled image, relabel each of the objects consecutively image - a labeled 2-d integer array returns - (labeled image, object count)
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L576-L596
CellProfiler/centrosome
centrosome/cpmorphology.py
convex_hull_image
def convex_hull_image(image): '''Given a binary image, return an image of the convex hull''' labels = image.astype(int) points, counts = convex_hull(labels, np.array([1])) output = np.zeros(image.shape, int) for i in range(counts[0]): inext = (i+1) % counts[0] draw_line(output, point...
python
def convex_hull_image(image): '''Given a binary image, return an image of the convex hull''' labels = image.astype(int) points, counts = convex_hull(labels, np.array([1])) output = np.zeros(image.shape, int) for i in range(counts[0]): inext = (i+1) % counts[0] draw_line(output, point...
Given a binary image, return an image of the convex hull
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L598-L607
CellProfiler/centrosome
centrosome/cpmorphology.py
convex_hull
def convex_hull(labels, indexes=None, fast=True): """Given a labeled image, return a list of points per object ordered by angle from an interior point, representing the convex hull.s labels - the label matrix indexes - an array of label #s to be processed, defaults to all non-zero lab...
python
def convex_hull(labels, indexes=None, fast=True): """Given a labeled image, return a list of points per object ordered by angle from an interior point, representing the convex hull.s labels - the label matrix indexes - an array of label #s to be processed, defaults to all non-zero lab...
Given a labeled image, return a list of points per object ordered by angle from an interior point, representing the convex hull.s labels - the label matrix indexes - an array of label #s to be processed, defaults to all non-zero labels Returns a matrix and a vector. The matrix co...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L609-L646
CellProfiler/centrosome
centrosome/cpmorphology.py
convex_hull_ijv
def convex_hull_ijv(pixel_labels, indexes, fast=True): '''Return the convex hull for each label using an ijv labeling pixel_labels: the labeling of the pixels in i,j,v form where i & j are the coordinates of a pixel and v is the pixel's label number indexes: the inde...
python
def convex_hull_ijv(pixel_labels, indexes, fast=True): '''Return the convex hull for each label using an ijv labeling pixel_labels: the labeling of the pixels in i,j,v form where i & j are the coordinates of a pixel and v is the pixel's label number indexes: the inde...
Return the convex hull for each label using an ijv labeling pixel_labels: the labeling of the pixels in i,j,v form where i & j are the coordinates of a pixel and v is the pixel's label number indexes: the indexes at which to measure the convex hull Returns a matrix ...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L648-L887
CellProfiler/centrosome
centrosome/cpmorphology.py
triangle_areas
def triangle_areas(p1,p2,p3): """Compute an array of triangle areas given three arrays of triangle pts p1,p2,p3 - three Nx2 arrays of points """ v1 = (p2 - p1).astype(np.float) v2 = (p3 - p1).astype(np.float) # Original: # cross1 = v1[:,1] * v2[:,0] # cross2 = v2[:,1] * v1[:,0] ...
python
def triangle_areas(p1,p2,p3): """Compute an array of triangle areas given three arrays of triangle pts p1,p2,p3 - three Nx2 arrays of points """ v1 = (p2 - p1).astype(np.float) v2 = (p3 - p1).astype(np.float) # Original: # cross1 = v1[:,1] * v2[:,0] # cross2 = v2[:,1] * v1[:,0] ...
Compute an array of triangle areas given three arrays of triangle pts p1,p2,p3 - three Nx2 arrays of points
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L889-L915
CellProfiler/centrosome
centrosome/cpmorphology.py
fill_convex_hulls
def fill_convex_hulls(ch_pts, ch_counts): '''Return the points within the convex hulls of objects ch_pts - a Nx3 array of columns of label #, i and j as output by convex_hull ch_counts - the number of points per object returns the points in ijv format. ''' if len(ch_pts) == 0: ...
python
def fill_convex_hulls(ch_pts, ch_counts): '''Return the points within the convex hulls of objects ch_pts - a Nx3 array of columns of label #, i and j as output by convex_hull ch_counts - the number of points per object returns the points in ijv format. ''' if len(ch_pts) == 0: ...
Return the points within the convex hulls of objects ch_pts - a Nx3 array of columns of label #, i and j as output by convex_hull ch_counts - the number of points per object returns the points in ijv format.
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L917-L997
CellProfiler/centrosome
centrosome/cpmorphology.py
draw_line
def draw_line(labels,pt0,pt1,value=1): """Draw a line between two points pt0, pt1 are in i,j format which is the reverse of x,y format Uses the Bresenham algorithm Some code transcribed from http://www.cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html """ y0,x0 = pt0 y1,x1 = pt1 diff...
python
def draw_line(labels,pt0,pt1,value=1): """Draw a line between two points pt0, pt1 are in i,j format which is the reverse of x,y format Uses the Bresenham algorithm Some code transcribed from http://www.cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html """ y0,x0 = pt0 y1,x1 = pt1 diff...
Draw a line between two points pt0, pt1 are in i,j format which is the reverse of x,y format Uses the Bresenham algorithm Some code transcribed from http://www.cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L999-L1033
CellProfiler/centrosome
centrosome/cpmorphology.py
get_line_pts
def get_line_pts(pt0i, pt0j, pt1i, pt1j): '''Retrieve the coordinates of the points along lines pt0i, pt0j - the starting coordinates of the lines (1-d nparray) pt1i, pt1j - the ending coordinates of the lines (1-d nparray) use the Bresenham algorithm to find the coordinates along the lines ...
python
def get_line_pts(pt0i, pt0j, pt1i, pt1j): '''Retrieve the coordinates of the points along lines pt0i, pt0j - the starting coordinates of the lines (1-d nparray) pt1i, pt1j - the ending coordinates of the lines (1-d nparray) use the Bresenham algorithm to find the coordinates along the lines ...
Retrieve the coordinates of the points along lines pt0i, pt0j - the starting coordinates of the lines (1-d nparray) pt1i, pt1j - the ending coordinates of the lines (1-d nparray) use the Bresenham algorithm to find the coordinates along the lines connectiong pt0 and pt1. pt01, pt0j, pt1i and p...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L1035-L1181
CellProfiler/centrosome
centrosome/cpmorphology.py
polygon_lines_to_mask
def polygon_lines_to_mask(pt0i, pt0j, pt1i, pt1j, shape): '''Convert a series of polygon lines to a background / foreground mask pt0i, pt0j, pt1i, pt1j - start / end points of lines. Points are rounded to the nearest integer coordinate if float. shape - shape of the ma...
python
def polygon_lines_to_mask(pt0i, pt0j, pt1i, pt1j, shape): '''Convert a series of polygon lines to a background / foreground mask pt0i, pt0j, pt1i, pt1j - start / end points of lines. Points are rounded to the nearest integer coordinate if float. shape - shape of the ma...
Convert a series of polygon lines to a background / foreground mask pt0i, pt0j, pt1i, pt1j - start / end points of lines. Points are rounded to the nearest integer coordinate if float. shape - shape of the mask array This algorithm assumes that the lines form clos...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L1183-L1282
CellProfiler/centrosome
centrosome/cpmorphology.py
fixup_scipy_ndimage_result
def fixup_scipy_ndimage_result(whatever_it_returned): """Convert a result from scipy.ndimage to a numpy array scipy.ndimage has the annoying habit of returning a single, bare value instead of an array if the indexes passed in are of length 1. For instance: scind.maximum(image, labels, [1]) retu...
python
def fixup_scipy_ndimage_result(whatever_it_returned): """Convert a result from scipy.ndimage to a numpy array scipy.ndimage has the annoying habit of returning a single, bare value instead of an array if the indexes passed in are of length 1. For instance: scind.maximum(image, labels, [1]) retu...
Convert a result from scipy.ndimage to a numpy array scipy.ndimage has the annoying habit of returning a single, bare value instead of an array if the indexes passed in are of length 1. For instance: scind.maximum(image, labels, [1]) returns a float but scind.maximum(image, labels, [1,2]) r...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L1284-L1297
CellProfiler/centrosome
centrosome/cpmorphology.py
centers_of_labels
def centers_of_labels(labels): '''Return the i,j coordinates of the centers of a labels matrix The result returned is an 2 x n numpy array where n is the number of the label minus one, result[0,x] is the i coordinate of the center and result[x,1] is the j coordinate of the center. You can unpac...
python
def centers_of_labels(labels): '''Return the i,j coordinates of the centers of a labels matrix The result returned is an 2 x n numpy array where n is the number of the label minus one, result[0,x] is the i coordinate of the center and result[x,1] is the j coordinate of the center. You can unpac...
Return the i,j coordinates of the centers of a labels matrix The result returned is an 2 x n numpy array where n is the number of the label minus one, result[0,x] is the i coordinate of the center and result[x,1] is the j coordinate of the center. You can unpack the result as "i,j = centers_of_labe...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L1299-L1318
CellProfiler/centrosome
centrosome/cpmorphology.py
maximum_position_of_labels
def maximum_position_of_labels(image, labels, indices): '''Return the i,j coordinates of the maximum value within each object image - measure the maximum within this image labels - use the objects within this labels matrix indices - label #s to measure The result returned is an 2 x n numpy...
python
def maximum_position_of_labels(image, labels, indices): '''Return the i,j coordinates of the maximum value within each object image - measure the maximum within this image labels - use the objects within this labels matrix indices - label #s to measure The result returned is an 2 x n numpy...
Return the i,j coordinates of the maximum value within each object image - measure the maximum within this image labels - use the objects within this labels matrix indices - label #s to measure The result returned is an 2 x n numpy array where n is the number of the label minus one, result...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L1320-L1340
CellProfiler/centrosome
centrosome/cpmorphology.py
minimum_enclosing_circle
def minimum_enclosing_circle(labels, indexes = None, hull_and_point_count = None): """Find the location of the minimum enclosing circle and its radius labels - a labels matrix indexes - an array giving the label indexes to be processed hull_and_point_count - convex_hul...
python
def minimum_enclosing_circle(labels, indexes = None, hull_and_point_count = None): """Find the location of the minimum enclosing circle and its radius labels - a labels matrix indexes - an array giving the label indexes to be processed hull_and_point_count - convex_hul...
Find the location of the minimum enclosing circle and its radius labels - a labels matrix indexes - an array giving the label indexes to be processed hull_and_point_count - convex_hull output if already done. None = calculate returns an Nx3 array organized as i,j of the center and radius A...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L1381-L1706
CellProfiler/centrosome
centrosome/cpmorphology.py
associate_by_distance
def associate_by_distance(labels_a, labels_b, distance): '''Find the objects that are within a given distance of each other Given two labels matrices and a distance, find pairs of objects that are within the given distance of each other where the distance is the minimum distance between any point i...
python
def associate_by_distance(labels_a, labels_b, distance): '''Find the objects that are within a given distance of each other Given two labels matrices and a distance, find pairs of objects that are within the given distance of each other where the distance is the minimum distance between any point i...
Find the objects that are within a given distance of each other Given two labels matrices and a distance, find pairs of objects that are within the given distance of each other where the distance is the minimum distance between any point in the convex hull of the two objects. labels_a - fi...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L1708-L1843
CellProfiler/centrosome
centrosome/cpmorphology.py
minimum_distance2
def minimum_distance2(hull_a, center_a, hull_b, center_b): '''Return the minimum distance or 0 if overlap between 2 convex hulls hull_a - list of points in clockwise direction center_a - a point within the hull hull_b - list of points in clockwise direction center_b - a point within the hull ...
python
def minimum_distance2(hull_a, center_a, hull_b, center_b): '''Return the minimum distance or 0 if overlap between 2 convex hulls hull_a - list of points in clockwise direction center_a - a point within the hull hull_b - list of points in clockwise direction center_b - a point within the hull ...
Return the minimum distance or 0 if overlap between 2 convex hulls hull_a - list of points in clockwise direction center_a - a point within the hull hull_b - list of points in clockwise direction center_b - a point within the hull
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L1845-L1856
CellProfiler/centrosome
centrosome/cpmorphology.py
slow_minimum_distance2
def slow_minimum_distance2(hull_a, hull_b): '''Do the minimum distance by exhaustive examination of all points''' d2_min = np.iinfo(int).max for a in hull_a: if within_hull(a, hull_b): return 0 for b in hull_b: if within_hull(b, hull_a): return 0 for pt_a in h...
python
def slow_minimum_distance2(hull_a, hull_b): '''Do the minimum distance by exhaustive examination of all points''' d2_min = np.iinfo(int).max for a in hull_a: if within_hull(a, hull_b): return 0 for b in hull_b: if within_hull(b, hull_a): return 0 for pt_a in h...
Do the minimum distance by exhaustive examination of all points
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L1858-L1882
CellProfiler/centrosome
centrosome/cpmorphology.py
faster_minimum_distance2
def faster_minimum_distance2(hull_a, center_a, hull_b, center_b): '''Do the minimum distance using the bimodal property of hull ordering ''' # # Find the farthest vertex in b from some point within A. Find the # vertices within A visible from this point in B. If the point in A # is within B...
python
def faster_minimum_distance2(hull_a, center_a, hull_b, center_b): '''Do the minimum distance using the bimodal property of hull ordering ''' # # Find the farthest vertex in b from some point within A. Find the # vertices within A visible from this point in B. If the point in A # is within B...
Do the minimum distance using the bimodal property of hull ordering
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L1884-L1970
CellProfiler/centrosome
centrosome/cpmorphology.py
lines_intersect
def lines_intersect(pt1_p, pt2_p, pt1_q, pt2_q): '''Return true if two line segments intersect pt1_p, pt2_p - endpoints of first line segment pt1_q, pt2_q - endpoints of second line segment ''' # # The idea here is to do the cross-product of the vector from # point 1 to point 2 of one segmen...
python
def lines_intersect(pt1_p, pt2_p, pt1_q, pt2_q): '''Return true if two line segments intersect pt1_p, pt2_p - endpoints of first line segment pt1_q, pt2_q - endpoints of second line segment ''' # # The idea here is to do the cross-product of the vector from # point 1 to point 2 of one segmen...
Return true if two line segments intersect pt1_p, pt2_p - endpoints of first line segment pt1_q, pt2_q - endpoints of second line segment
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L1972-L1996
CellProfiler/centrosome
centrosome/cpmorphology.py
find_farthest
def find_farthest(point, hull): '''Find the vertex in hull farthest away from a point''' d_start = np.sum((point-hull[0,:])**2) d_end = np.sum((point-hull[-1,:])**2) if d_start > d_end: # Go in the forward direction i = 1 inc = 1 term = hull.shape[0] d2_max = d_st...
python
def find_farthest(point, hull): '''Find the vertex in hull farthest away from a point''' d_start = np.sum((point-hull[0,:])**2) d_end = np.sum((point-hull[-1,:])**2) if d_start > d_end: # Go in the forward direction i = 1 inc = 1 term = hull.shape[0] d2_max = d_st...
Find the vertex in hull farthest away from a point
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2003-L2025
CellProfiler/centrosome
centrosome/cpmorphology.py
find_visible
def find_visible(hull, observer, background): '''Given an observer location, find the first and last visible points in the hull The observer at "observer" is looking at the hull whose most distant vertex from the observer is "background. Find the vertices that are the furthest di...
python
def find_visible(hull, observer, background): '''Given an observer location, find the first and last visible points in the hull The observer at "observer" is looking at the hull whose most distant vertex from the observer is "background. Find the vertices that are the furthest di...
Given an observer location, find the first and last visible points in the hull The observer at "observer" is looking at the hull whose most distant vertex from the observer is "background. Find the vertices that are the furthest distance from the line between observer and background....
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2027-L2061
CellProfiler/centrosome
centrosome/cpmorphology.py
distance2_to_line
def distance2_to_line(pt, l0, l1): '''The perpendicular distance squared from a point to a line pt - point in question l0 - one point on the line l1 - another point on the line ''' pt = np.atleast_1d(pt) l0 = np.atleast_1d(l0) l1 = np.atleast_1d(l1) reshape = pt.ndim == 1 if...
python
def distance2_to_line(pt, l0, l1): '''The perpendicular distance squared from a point to a line pt - point in question l0 - one point on the line l1 - another point on the line ''' pt = np.atleast_1d(pt) l0 = np.atleast_1d(l0) l1 = np.atleast_1d(l1) reshape = pt.ndim == 1 if...
The perpendicular distance squared from a point to a line pt - point in question l0 - one point on the line l1 - another point on the line
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2063-L2081
CellProfiler/centrosome
centrosome/cpmorphology.py
within_hull
def within_hull(point, hull): '''Return true if the point is within the convex hull''' h_prev_pt = hull[-1,:] for h_pt in hull: if np.cross(h_pt-h_prev_pt, point - h_pt) >= 0: return False h_prev_pt = h_pt return True
python
def within_hull(point, hull): '''Return true if the point is within the convex hull''' h_prev_pt = hull[-1,:] for h_pt in hull: if np.cross(h_pt-h_prev_pt, point - h_pt) >= 0: return False h_prev_pt = h_pt return True
Return true if the point is within the convex hull
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2084-L2091
CellProfiler/centrosome
centrosome/cpmorphology.py
all_true
def all_true(a, indexes): '''Find which vectors have all-true elements Given an array, "a" and indexes into the first elements of vectors within that array, return an array where each element is true if all elements of the corresponding vector are true. Example: a = [ 1,1,0,1,1,1,1], index...
python
def all_true(a, indexes): '''Find which vectors have all-true elements Given an array, "a" and indexes into the first elements of vectors within that array, return an array where each element is true if all elements of the corresponding vector are true. Example: a = [ 1,1,0,1,1,1,1], index...
Find which vectors have all-true elements Given an array, "a" and indexes into the first elements of vectors within that array, return an array where each element is true if all elements of the corresponding vector are true. Example: a = [ 1,1,0,1,1,1,1], indexes=[0,3] vectors = [...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2093-L2115
CellProfiler/centrosome
centrosome/cpmorphology.py
ellipse_from_second_moments
def ellipse_from_second_moments(image, labels, indexes, wants_compactness = False): """Calculate measurements of ellipses equivalent to the second moments of labels image - the intensity at each point labels - for each labeled object, derive an ellipse indexes - sequence of indexes to process ...
python
def ellipse_from_second_moments(image, labels, indexes, wants_compactness = False): """Calculate measurements of ellipses equivalent to the second moments of labels image - the intensity at each point labels - for each labeled object, derive an ellipse indexes - sequence of indexes to process ...
Calculate measurements of ellipses equivalent to the second moments of labels image - the intensity at each point labels - for each labeled object, derive an ellipse indexes - sequence of indexes to process returns the following arrays: coordinates of the center of the ellipse e...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2117-L2149
CellProfiler/centrosome
centrosome/cpmorphology.py
ellipse_from_second_moments_ijv
def ellipse_from_second_moments_ijv(i,j, image, labels, indexes, wants_compactness = False): """Calculate measurements of ellipses equivalent to the second moments of labels i,j - coordinates of each point image - the intensity at each point labels - for each labeled object, derive an ellipse ...
python
def ellipse_from_second_moments_ijv(i,j, image, labels, indexes, wants_compactness = False): """Calculate measurements of ellipses equivalent to the second moments of labels i,j - coordinates of each point image - the intensity at each point labels - for each labeled object, derive an ellipse ...
Calculate measurements of ellipses equivalent to the second moments of labels i,j - coordinates of each point image - the intensity at each point labels - for each labeled object, derive an ellipse indexes - sequence of indexes to process returns the following arrays: coordinates o...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2151-L2233
CellProfiler/centrosome
centrosome/cpmorphology.py
calculate_extents
def calculate_extents(labels, indexes): """Return the area of each object divided by the area of its bounding box""" fix = fixup_scipy_ndimage_result areas = fix(scind.sum(np.ones(labels.shape),labels,np.array(indexes, dtype=np.int32))) y,x = np.mgrid[0:labels.shape[0],0:labels.shape[1]] xmin = fix(...
python
def calculate_extents(labels, indexes): """Return the area of each object divided by the area of its bounding box""" fix = fixup_scipy_ndimage_result areas = fix(scind.sum(np.ones(labels.shape),labels,np.array(indexes, dtype=np.int32))) y,x = np.mgrid[0:labels.shape[0],0:labels.shape[1]] xmin = fix(...
Return the area of each object divided by the area of its bounding box
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2235-L2245
CellProfiler/centrosome
centrosome/cpmorphology.py
__calculate_perimeter_scoring
def __calculate_perimeter_scoring(): """Return a 512 element vector which gives the perimeter given surrounding pts """ # # This is the array from the paper - a 256 - element array leaving out # the center point. The first value is the index, the second, the perimeter # prashker = np.ar...
python
def __calculate_perimeter_scoring(): """Return a 512 element vector which gives the perimeter given surrounding pts """ # # This is the array from the paper - a 256 - element array leaving out # the center point. The first value is the index, the second, the perimeter # prashker = np.ar...
Return a 512 element vector which gives the perimeter given surrounding pts
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2260-L2309
CellProfiler/centrosome
centrosome/cpmorphology.py
calculate_perimeters
def calculate_perimeters(labels, indexes): """Count the distances between adjacent pixels in the perimeters of the labels""" # # Create arrays that tell whether a pixel is like its neighbors. # index = 0 is the pixel -1,-1 from the pixel of interest, 1 is -1,0, etc. # m = table_idx_from_labels(l...
python
def calculate_perimeters(labels, indexes): """Count the distances between adjacent pixels in the perimeters of the labels""" # # Create arrays that tell whether a pixel is like its neighbors. # index = 0 is the pixel -1,-1 from the pixel of interest, 1 is -1,0, etc. # m = table_idx_from_labels(l...
Count the distances between adjacent pixels in the perimeters of the labels
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2313-L2321
CellProfiler/centrosome
centrosome/cpmorphology.py
table_idx_from_labels
def table_idx_from_labels(labels): '''Return an array of indexes into a morphology lookup table labels - a labels matrix returns a matrix of values between 0 and 511 of indices appropriate for table_lookup where a pixel's index is determined based on whether or not the pixel has the same label ...
python
def table_idx_from_labels(labels): '''Return an array of indexes into a morphology lookup table labels - a labels matrix returns a matrix of values between 0 and 511 of indices appropriate for table_lookup where a pixel's index is determined based on whether or not the pixel has the same label ...
Return an array of indexes into a morphology lookup table labels - a labels matrix returns a matrix of values between 0 and 511 of indices appropriate for table_lookup where a pixel's index is determined based on whether or not the pixel has the same label as its neighbors (and is labeled)
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2323-L2348
CellProfiler/centrosome
centrosome/cpmorphology.py
calculate_convex_hull_areas
def calculate_convex_hull_areas(labels,indexes=None): """Calulculate the area of the convex hull of each labeled object labels - a label matrix indexes - None: calculate convex hull area over entire image number: calculate convex hull for a single label sequence: calculate c...
python
def calculate_convex_hull_areas(labels,indexes=None): """Calulculate the area of the convex hull of each labeled object labels - a label matrix indexes - None: calculate convex hull area over entire image number: calculate convex hull for a single label sequence: calculate c...
Calulculate the area of the convex hull of each labeled object labels - a label matrix indexes - None: calculate convex hull area over entire image number: calculate convex hull for a single label sequence: calculate convex hull for labels matching a sequence ...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2350-L2464
CellProfiler/centrosome
centrosome/cpmorphology.py
calculate_solidity
def calculate_solidity(labels,indexes=None): """Calculate the area of each label divided by the area of its convex hull labels - a label matrix indexes - the indexes of the labels to measure """ if indexes is not None: """ Convert to compat 32bit integer """ indexes = np.array(i...
python
def calculate_solidity(labels,indexes=None): """Calculate the area of each label divided by the area of its convex hull labels - a label matrix indexes - the indexes of the labels to measure """ if indexes is not None: """ Convert to compat 32bit integer """ indexes = np.array(i...
Calculate the area of each label divided by the area of its convex hull labels - a label matrix indexes - the indexes of the labels to measure
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2466-L2477
CellProfiler/centrosome
centrosome/cpmorphology.py
euler_number
def euler_number(labels, indexes=None): """Calculate the Euler number of each label labels - a label matrix indexes - the indexes of the labels to measure or None to treat the labels matrix as a binary matrix """ if indexes is None: labels = labels != 0 indexes = n...
python
def euler_number(labels, indexes=None): """Calculate the Euler number of each label labels - a label matrix indexes - the indexes of the labels to measure or None to treat the labels matrix as a binary matrix """ if indexes is None: labels = labels != 0 indexes = n...
Calculate the Euler number of each label labels - a label matrix indexes - the indexes of the labels to measure or None to treat the labels matrix as a binary matrix
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2479-L2592
CellProfiler/centrosome
centrosome/cpmorphology.py
block
def block(shape, block_shape): """Create a labels image that divides the image into blocks shape - the shape of the image to be blocked block_shape - the shape of one block returns a labels matrix and the indexes of all labels generated The idea here is to block-process an image by us...
python
def block(shape, block_shape): """Create a labels image that divides the image into blocks shape - the shape of the image to be blocked block_shape - the shape of one block returns a labels matrix and the indexes of all labels generated The idea here is to block-process an image by us...
Create a labels image that divides the image into blocks shape - the shape of the image to be blocked block_shape - the shape of one block returns a labels matrix and the indexes of all labels generated The idea here is to block-process an image by using SciPy label routines. This rou...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2594-L2622
CellProfiler/centrosome
centrosome/cpmorphology.py
white_tophat
def white_tophat(image, radius=None, mask=None, footprint=None): '''White tophat filter an image using a circular structuring element image - image in question radius - radius of the circular structuring element. If no radius, use an 8-connected structuring element. mask - mask of sig...
python
def white_tophat(image, radius=None, mask=None, footprint=None): '''White tophat filter an image using a circular structuring element image - image in question radius - radius of the circular structuring element. If no radius, use an 8-connected structuring element. mask - mask of sig...
White tophat filter an image using a circular structuring element image - image in question radius - radius of the circular structuring element. If no radius, use an 8-connected structuring element. mask - mask of significant pixels in the image. Points outside of the mask wil...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2624-L2643
CellProfiler/centrosome
centrosome/cpmorphology.py
black_tophat
def black_tophat(image, radius=None, mask=None, footprint=None): '''Black tophat filter an image using a circular structuring element image - image in question radius - radius of the circular structuring element. If no radius, use an 8-connected structuring element. mask - mask of sig...
python
def black_tophat(image, radius=None, mask=None, footprint=None): '''Black tophat filter an image using a circular structuring element image - image in question radius - radius of the circular structuring element. If no radius, use an 8-connected structuring element. mask - mask of sig...
Black tophat filter an image using a circular structuring element image - image in question radius - radius of the circular structuring element. If no radius, use an 8-connected structuring element. mask - mask of significant pixels in the image. Points outside of the mask wil...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2645-L2664
CellProfiler/centrosome
centrosome/cpmorphology.py
grey_erosion
def grey_erosion(image, radius=None, mask=None, footprint=None): '''Perform a grey erosion with masking''' if footprint is None: if radius is None: footprint = np.ones((3,3),bool) radius = 1 else: footprint = strel_disk(radius)==1 else: radius = ma...
python
def grey_erosion(image, radius=None, mask=None, footprint=None): '''Perform a grey erosion with masking''' if footprint is None: if radius is None: footprint = np.ones((3,3),bool) radius = 1 else: footprint = strel_disk(radius)==1 else: radius = ma...
Perform a grey erosion with masking
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2666-L2689
CellProfiler/centrosome
centrosome/cpmorphology.py
grey_reconstruction
def grey_reconstruction(image, mask, footprint=None, offset=None): '''Perform a morphological reconstruction of the image grey_dilate the image, constraining each pixel to have a value that is at most that of the mask. image - the seed image mask - the mask, giving the maximum allowed value at ...
python
def grey_reconstruction(image, mask, footprint=None, offset=None): '''Perform a morphological reconstruction of the image grey_dilate the image, constraining each pixel to have a value that is at most that of the mask. image - the seed image mask - the mask, giving the maximum allowed value at ...
Perform a morphological reconstruction of the image grey_dilate the image, constraining each pixel to have a value that is at most that of the mask. image - the seed image mask - the mask, giving the maximum allowed value at each point footprint - a boolean array giving the neighborhood pixels ...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2719-L2836
CellProfiler/centrosome
centrosome/cpmorphology.py
opening
def opening(image, radius=None, mask=None, footprint=None): '''Do a morphological opening image - pixel image to operate on radius - use a structuring element with the given radius. If no radius, use an 8-connected structuring element. mask - if present, only use unmasked pixels for op...
python
def opening(image, radius=None, mask=None, footprint=None): '''Do a morphological opening image - pixel image to operate on radius - use a structuring element with the given radius. If no radius, use an 8-connected structuring element. mask - if present, only use unmasked pixels for op...
Do a morphological opening image - pixel image to operate on radius - use a structuring element with the given radius. If no radius, use an 8-connected structuring element. mask - if present, only use unmasked pixels for operations
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2838-L2847
CellProfiler/centrosome
centrosome/cpmorphology.py
closing
def closing(image, radius=None, mask=None, footprint = None): '''Do a morphological closing image - pixel image to operate on radius - use a structuring element with the given radius. If no structuring element, use an 8-connected structuring element. mask - if present, only use unmaske...
python
def closing(image, radius=None, mask=None, footprint = None): '''Do a morphological closing image - pixel image to operate on radius - use a structuring element with the given radius. If no structuring element, use an 8-connected structuring element. mask - if present, only use unmaske...
Do a morphological closing image - pixel image to operate on radius - use a structuring element with the given radius. If no structuring element, use an 8-connected structuring element. mask - if present, only use unmasked pixels for operations
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2849-L2858
CellProfiler/centrosome
centrosome/cpmorphology.py
openlines
def openlines(image, linelength=10, dAngle=10, mask=None): """ Do a morphological opening along lines of different angles. Return difference between max and min response to different angles for each pixel. This effectively removes dots and only keeps lines. image - pixel image to operate on le...
python
def openlines(image, linelength=10, dAngle=10, mask=None): """ Do a morphological opening along lines of different angles. Return difference between max and min response to different angles for each pixel. This effectively removes dots and only keeps lines. image - pixel image to operate on le...
Do a morphological opening along lines of different angles. Return difference between max and min response to different angles for each pixel. This effectively removes dots and only keeps lines. image - pixel image to operate on length - length of the structural element angluar_resolution - angle ...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2860-L2881
CellProfiler/centrosome
centrosome/cpmorphology.py
table_lookup
def table_lookup(image, table, border_value, iterations = None): '''Perform a morphological transform on an image, directed by its neighbors image - a binary image table - a 512-element table giving the transform of each pixel given the values of that pixel and its 8-connected neighbors. ...
python
def table_lookup(image, table, border_value, iterations = None): '''Perform a morphological transform on an image, directed by its neighbors image - a binary image table - a 512-element table giving the transform of each pixel given the values of that pixel and its 8-connected neighbors. ...
Perform a morphological transform on an image, directed by its neighbors image - a binary image table - a 512-element table giving the transform of each pixel given the values of that pixel and its 8-connected neighbors. border_value - the value of pixels beyond the border of the image. ...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2883-L2960
CellProfiler/centrosome
centrosome/cpmorphology.py
pattern_of
def pattern_of(index): '''Return the pattern represented by an index value''' return np.array([[index & 2**0,index & 2**1,index & 2**2], [index & 2**3,index & 2**4,index & 2**5], [index & 2**6,index & 2**7,index & 2**8]], bool)
python
def pattern_of(index): '''Return the pattern represented by an index value''' return np.array([[index & 2**0,index & 2**1,index & 2**2], [index & 2**3,index & 2**4,index & 2**5], [index & 2**6,index & 2**7,index & 2**8]], bool)
Return the pattern represented by an index value
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2962-L2966
CellProfiler/centrosome
centrosome/cpmorphology.py
index_of
def index_of(pattern): '''Return the index of a given pattern''' return (pattern[0,0] * 2**0 + pattern[0,1] * 2**1 + pattern[0,2] * 2**2 + pattern[1,0] * 2**3 + pattern[1,1] * 2**4 + pattern[1,2] * 2**5 + pattern[2,0] * 2**6 + pattern[2,1] * 2**7 + pattern[2,2] * 2**8)
python
def index_of(pattern): '''Return the index of a given pattern''' return (pattern[0,0] * 2**0 + pattern[0,1] * 2**1 + pattern[0,2] * 2**2 + pattern[1,0] * 2**3 + pattern[1,1] * 2**4 + pattern[1,2] * 2**5 + pattern[2,0] * 2**6 + pattern[2,1] * 2**7 + pattern[2,2] * 2**8)
Return the index of a given pattern
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2968-L2972
CellProfiler/centrosome
centrosome/cpmorphology.py
make_table
def make_table(value, pattern, care=np.ones((3,3),bool)): '''Return a table suitable for table_lookup value - set all table entries matching "pattern" to "value", all others to not "value" pattern - a 3x3 boolean array with the pattern to match care - a 3x3 boolean array where each v...
python
def make_table(value, pattern, care=np.ones((3,3),bool)): '''Return a table suitable for table_lookup value - set all table entries matching "pattern" to "value", all others to not "value" pattern - a 3x3 boolean array with the pattern to match care - a 3x3 boolean array where each v...
Return a table suitable for table_lookup value - set all table entries matching "pattern" to "value", all others to not "value" pattern - a 3x3 boolean array with the pattern to match care - a 3x3 boolean array where each value is true if the pattern must match at that posi...
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L2974-L2992
CellProfiler/centrosome
centrosome/cpmorphology.py
branchpoints
def branchpoints(image, mask=None): '''Remove all pixels from an image except for branchpoints image - a skeletonized image mask - a mask of pixels excluded from consideration 1 0 1 ? 0 ? 0 1 0 -> 0 1 0 0 1 0 0 ? 0 ''' global branchpoints_table if mask is None: ...
python
def branchpoints(image, mask=None): '''Remove all pixels from an image except for branchpoints image - a skeletonized image mask - a mask of pixels excluded from consideration 1 0 1 ? 0 ? 0 1 0 -> 0 1 0 0 1 0 0 ? 0 ''' global branchpoints_table if mask is None: ...
Remove all pixels from an image except for branchpoints image - a skeletonized image mask - a mask of pixels excluded from consideration 1 0 1 ? 0 ? 0 1 0 -> 0 1 0 0 1 0 0 ? 0
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3006-L3025
CellProfiler/centrosome
centrosome/cpmorphology.py
branchings
def branchings(image, mask=None): '''Count the number of branches eminating from each pixel image - a binary image mask - optional mask of pixels not to consider This is the count of the number of branches that eminate from a pixel. A pixel with neighbors fore and aft has branches fore and...
python
def branchings(image, mask=None): '''Count the number of branches eminating from each pixel image - a binary image mask - optional mask of pixels not to consider This is the count of the number of branches that eminate from a pixel. A pixel with neighbors fore and aft has branches fore and...
Count the number of branches eminating from each pixel image - a binary image mask - optional mask of pixels not to consider This is the count of the number of branches that eminate from a pixel. A pixel with neighbors fore and aft has branches fore and aft = 2. An endpoint has one branch....
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3043-L3074
CellProfiler/centrosome
centrosome/cpmorphology.py
bridge
def bridge(image, mask=None, iterations = 1): '''Fill in pixels that bridge gaps. 1 0 0 1 0 0 0 0 0 -> 0 1 0 0 0 1 0 0 1 ''' global bridge_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[~mask] = F...
python
def bridge(image, mask=None, iterations = 1): '''Fill in pixels that bridge gaps. 1 0 0 1 0 0 0 0 0 -> 0 1 0 0 0 1 0 0 1 ''' global bridge_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[~mask] = F...
Fill in pixels that bridge gaps. 1 0 0 1 0 0 0 0 0 -> 0 1 0 0 0 1 0 0 1
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3086-L3102
CellProfiler/centrosome
centrosome/cpmorphology.py
clean
def clean(image, mask=None, iterations = 1): '''Remove isolated pixels 0 0 0 0 0 0 0 1 0 -> 0 0 0 0 0 0 0 0 0 Border pixels and pixels adjoining masks are removed unless one valid neighbor is true. ''' global clean_table if mask is None: masked_image = imag...
python
def clean(image, mask=None, iterations = 1): '''Remove isolated pixels 0 0 0 0 0 0 0 1 0 -> 0 0 0 0 0 0 0 0 0 Border pixels and pixels adjoining masks are removed unless one valid neighbor is true. ''' global clean_table if mask is None: masked_image = imag...
Remove isolated pixels 0 0 0 0 0 0 0 1 0 -> 0 0 0 0 0 0 0 0 0 Border pixels and pixels adjoining masks are removed unless one valid neighbor is true.
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3109-L3128
CellProfiler/centrosome
centrosome/cpmorphology.py
diag
def diag(image, mask=None, iterations=1): '''4-connect pixels that are 8-connected 0 0 0 0 0 ? 0 0 1 -> 0 1 1 0 1 0 ? 1 ? ''' global diag_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[~ma...
python
def diag(image, mask=None, iterations=1): '''4-connect pixels that are 8-connected 0 0 0 0 0 ? 0 0 1 -> 0 1 1 0 1 0 ? 1 ? ''' global diag_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[~ma...
4-connect pixels that are 8-connected 0 0 0 0 0 ? 0 0 1 -> 0 1 1 0 1 0 ? 1 ?
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3159-L3176
CellProfiler/centrosome
centrosome/cpmorphology.py
endpoints
def endpoints(image, mask=None): '''Remove all pixels from an image except for endpoints image - a skeletonized image mask - a mask of pixels excluded from consideration 1 0 0 ? 0 0 0 1 0 -> 0 1 0 0 0 0 0 0 0 ''' global endpoints_table if mask is None: masked...
python
def endpoints(image, mask=None): '''Remove all pixels from an image except for endpoints image - a skeletonized image mask - a mask of pixels excluded from consideration 1 0 0 ? 0 0 0 1 0 -> 0 1 0 0 0 0 0 0 0 ''' global endpoints_table if mask is None: masked...
Remove all pixels from an image except for endpoints image - a skeletonized image mask - a mask of pixels excluded from consideration 1 0 0 ? 0 0 0 1 0 -> 0 1 0 0 0 0 0 0 0
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3185-L3204
CellProfiler/centrosome
centrosome/cpmorphology.py
fill
def fill(image, mask=None, iterations=1): '''Fill isolated black pixels 1 1 1 1 1 1 1 0 1 -> 1 1 1 1 1 1 1 1 1 ''' global fill_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[~mask] = True r...
python
def fill(image, mask=None, iterations=1): '''Fill isolated black pixels 1 1 1 1 1 1 1 0 1 -> 1 1 1 1 1 1 1 1 1 ''' global fill_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[~mask] = True r...
Fill isolated black pixels 1 1 1 1 1 1 1 0 1 -> 1 1 1 1 1 1 1 1 1
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3211-L3227
CellProfiler/centrosome
centrosome/cpmorphology.py
fill4
def fill4(image, mask=None, iterations=1): '''Fill 4-connected black pixels x 1 x x 1 x 1 0 1 -> 1 1 1 x 1 x x 1 x ''' global fill4_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[~mask] = True ...
python
def fill4(image, mask=None, iterations=1): '''Fill 4-connected black pixels x 1 x x 1 x 1 0 1 -> 1 1 1 x 1 x x 1 x ''' global fill4_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[~mask] = True ...
Fill 4-connected black pixels x 1 x x 1 x 1 0 1 -> 1 1 1 x 1 x x 1 x
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3236-L3252
CellProfiler/centrosome
centrosome/cpmorphology.py
hbreak
def hbreak(image, mask=None, iterations=1): '''Remove horizontal breaks 1 1 1 1 1 1 0 1 0 -> 0 0 0 (this case only) 1 1 1 1 1 1 ''' global hbreak_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[...
python
def hbreak(image, mask=None, iterations=1): '''Remove horizontal breaks 1 1 1 1 1 1 0 1 0 -> 0 0 0 (this case only) 1 1 1 1 1 1 ''' global hbreak_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[...
Remove horizontal breaks 1 1 1 1 1 1 0 1 0 -> 0 0 0 (this case only) 1 1 1 1 1 1
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3260-L3276
CellProfiler/centrosome
centrosome/cpmorphology.py
vbreak
def vbreak(image, mask=None, iterations=1): '''Remove horizontal breaks 1 1 1 1 1 1 0 1 0 -> 0 0 0 (this case only) 1 1 1 1 1 1 ''' global vbreak_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[...
python
def vbreak(image, mask=None, iterations=1): '''Remove horizontal breaks 1 1 1 1 1 1 0 1 0 -> 0 0 0 (this case only) 1 1 1 1 1 1 ''' global vbreak_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[...
Remove horizontal breaks 1 1 1 1 1 1 0 1 0 -> 0 0 0 (this case only) 1 1 1 1 1 1
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3284-L3300
CellProfiler/centrosome
centrosome/cpmorphology.py
majority
def majority(image, mask=None, iterations=1): '''A pixel takes the value of the majority of its neighbors ''' global majority_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[~mask] = False result = table_lookup(...
python
def majority(image, mask=None, iterations=1): '''A pixel takes the value of the majority of its neighbors ''' global majority_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[~mask] = False result = table_lookup(...
A pixel takes the value of the majority of its neighbors
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3312-L3325
CellProfiler/centrosome
centrosome/cpmorphology.py
remove
def remove(image, mask=None, iterations=1): '''Turn 1 pixels to 0 if their 4-connected neighbors are all 0 ? 1 ? ? 1 ? 1 1 1 -> 1 0 1 ? 1 ? ? 1 ? ''' global remove_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() ...
python
def remove(image, mask=None, iterations=1): '''Turn 1 pixels to 0 if their 4-connected neighbors are all 0 ? 1 ? ? 1 ? 1 1 1 -> 1 0 1 ? 1 ? ? 1 ? ''' global remove_table if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() ...
Turn 1 pixels to 0 if their 4-connected neighbors are all 0 ? 1 ? ? 1 ? 1 1 1 -> 1 0 1 ? 1 ? ? 1 ?
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3340-L3356
CellProfiler/centrosome
centrosome/cpmorphology.py
spur
def spur(image, mask=None, iterations=1): '''Remove spur pixels from an image 0 0 0 0 0 0 0 1 0 -> 0 0 0 0 0 1 0 0 ? ''' global spur_table_1,spur_table_2 if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[~...
python
def spur(image, mask=None, iterations=1): '''Remove spur pixels from an image 0 0 0 0 0 0 0 1 0 -> 0 0 0 0 0 1 0 0 ? ''' global spur_table_1,spur_table_2 if mask is None: masked_image = image else: masked_image = image.astype(bool).copy() masked_image[~...
Remove spur pixels from an image 0 0 0 0 0 0 0 1 0 -> 0 0 0 0 0 1 0 0 ?
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3378-L3402
CellProfiler/centrosome
centrosome/cpmorphology.py
thicken
def thicken(image, mask=None, iterations=1): '''Thicken the objects in an image where doing so does not connect them 0 0 0 ? ? ? 0 0 0 -> ? 1 ? 0 0 1 ? ? ? 1 0 0 ? ? ? 0 0 0 -> ? 0 ? 0 0 1 ? ? ? ''' global thicken_table if mask is None: masked_image ...
python
def thicken(image, mask=None, iterations=1): '''Thicken the objects in an image where doing so does not connect them 0 0 0 ? ? ? 0 0 0 -> ? 1 ? 0 0 1 ? ? ? 1 0 0 ? ? ? 0 0 0 -> ? 0 ? 0 0 1 ? ? ? ''' global thicken_table if mask is None: masked_image ...
Thicken the objects in an image where doing so does not connect them 0 0 0 ? ? ? 0 0 0 -> ? 1 ? 0 0 1 ? ? ? 1 0 0 ? ? ? 0 0 0 -> ? 0 ? 0 0 1 ? ? ?
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3412-L3432
CellProfiler/centrosome
centrosome/cpmorphology.py
thin
def thin(image, mask=None, iterations=1): '''Thin an image to lines, preserving Euler number Implements thinning as described in algorithm # 1 from Guo, "Parallel Thinning with Two Subiteration Algorithms", Communications of the ACM, Vol 32 #3 page 359. ''' global thin_table, eight_connect ...
python
def thin(image, mask=None, iterations=1): '''Thin an image to lines, preserving Euler number Implements thinning as described in algorithm # 1 from Guo, "Parallel Thinning with Two Subiteration Algorithms", Communications of the ACM, Vol 32 #3 page 359. ''' global thin_table, eight_connect ...
Thin an image to lines, preserving Euler number Implements thinning as described in algorithm # 1 from Guo, "Parallel Thinning with Two Subiteration Algorithms", Communications of the ACM, Vol 32 #3 page 359.
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3456-L3505