magmap.cv.colocalizer module¶
Colocalize objects in an image, typically in separate channels.
- class magmap.cv.colocalizer.BlobMatch(matches=None, match_id=None, roi_id=None, blob1_id=None, blob2_id=None, df=None)[source]¶
Bases:
objectBlob match storage class as a wrapper for a data frame of matches.
- Variables:
df – Data frame of matches with column names given by
BlobMatch.Cols; defaults to None.coords – Blob match coordinates, typically the mean coordinates of each blob pair; defaults to None.
cmap – Colormap for each match; defaults to None.
- class Cols(value)[source]¶
Bases:
EnumBlob match column names.
- BLOB1 = 'Blob1'¶
- BLOB1_ID = 'Blob1ID'¶
- BLOB2 = 'Blob2'¶
- BLOB2_ID = 'Blob2ID'¶
- DIST = 'Distance'¶
- MATCH_ID = 'MatchID'¶
- ROI_ID = 'RoiID'¶
- get_mean_coords()[source]¶
Get mean value of each pair of matched blobs.
- Returns:
[n, 3]array ofnblob pairs, also set tocoords.
- update_blobs(fn, *args)[source]¶
Update all blobs with the given function.
- Parameters:
fn (func) – Function that accepts the output of
get_blobs()separately for each set of blobs.*args (Any) – Additional arguments to
fn.
- class magmap.cv.colocalizer.StackColocalizer[source]¶
Bases:
objectColocalize blobs in blocks based on matching blobs across channels.
Support shared memory for spawned multiprocessing, with fallback to pickling in forked multiprocessing.
- classmethod colocalize_block(coord, offset, shape, blobs=None, tol=None, setup_cli=False, channels=None)[source]¶
Colocalize blobs from different channels within a block.
- Parameters:
offset (
Sequence[int]) – Block offset within the full image in z,y,x.blobs (
Optional[Blobs], default:None) – Blobs; defaults to None, which will useblobs.tol (
Optional[Sequence[float]], default:None) – Tolerance for colocalizing blobs; defaults to None to usematch_tol.setup_cli (
bool, default:False) – True to set up CLI arguments, typically for a spawned (rather than forked) environment; defaults to False.channels (
Optional[Sequence[int]], default:None) – Channels to match; defaults to None, wherechannelswill be used.
- Returns:
coord:coord, for tracking multiprocessingmatches: dictionary of matches
- Return type:
Tuple of
- magmap.cv.colocalizer.colocalize_blobs(roi, blobs, thresh=None)[source]¶
Co-localize blobs from different channels based on surrounding intensities.
Thresholds for detection are first identified in each channel by taking the blobs in the given channel, finding the surrounding intensities, and taking a low (5th) percentile. Then for each channel, the surrounding intensities of blobs in that channel are compared with the thresholds in the other channels. Blobs exceeding any given threshold are considered to co-localize in that channel.
- Parameters:
roi (
np.ndarray) – Region of interest as a 3D+channel array.blobs (
np.ndarray) – Blobs as a 2D array in the format[[z, y, x, radius, confirmation, truth, channel...], ...].thresh (int, float, str) – Threshold percentile of intensities from pixels surrounding each blob in the given channel. Use “min” to instead take the mininimum average intensity of all blobs in the channel. Defaults to None to use “min”.
- Returns:
2D Numpy array of same length as
blobswith a column for each channel where 1 indicates that the corresponding blob has signal is present in the given channels at the blob’s location, and 0 indicates insufficient signal.- Return type:
np.ndarray
- magmap.cv.colocalizer.colocalize_blobs_match(blobs, offset, size, tol, inner_padding=None, channels=None)[source]¶
Co-localize blobs in separate channels but the same ROI by finding optimal blob matches.
- Parameters:
blobs (
Blobs) – Blobs.tol (
Sequence[float]) – Tolerances for matching given as x,y,zinner_padding (
Optional[Sequence[int]], default:None) – ROI padding given as x,y,z; defaults to None to use the padding based ontol.channels (
Optional[Sequence[int]], default:None) – Indices of channels to colocalize. Defaults to None, which will use all channels inblobs.
- Return type:
- Returns:
Dictionary where keys are tuples of the two channels compared and values are blob matches objects, or None if
blobsis None.
- magmap.cv.colocalizer.insert_matches(db, matches)[source]¶
Insert matches into database for a whole image.
- Parameters:
db (
sqlite.ClrDB) – Database object.matches (dict[tuple[int, int],
BlobMatch) – Dictionary of channel combo tuples to blob match objects.
- magmap.cv.colocalizer.select_matches(db, channels, offset=None, shape=None, exp_name=None)[source]¶
Select blob matches for the given region from a database.
Blob matches are assumed to have been processed from the whole image. To retrieve matches from a selected ROI, use
magmap.io.sqlite.ClrDB.select_blob_matches()instead.- Parameters:
- Returns:
Dictionary where keys are tuples of the two channels compared and values are a list of blob matches. None if no blob matches are found.
- Return type:
dict[tuple[int, int], list[
BlobMatch]