Generate 2D patches
Short Description
The generateSinglePatch function facilitates the extraction of individual image patches centered around single-cell coordinates from a larger image, offering the flexibility to specify which markers or channels to include.
Function¶
generateSinglePatch(spatialTablePath, imagePath, imageName='test_image', markerChannelMapPath=None, markers=['DNA1'], markerColumnName='marker', channelColumnName='channel', x_coordinate='X_centroid', y_coordinate='Y_centroid', cell_indicator='CellID', cropsize=16, image_fraction=1, random_state=1, verbose=True, projectDir=None)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spatialTablePath |
str
|
Path to the single-cell spatial feature matrix, typically a CSV file. |
required |
imagePath |
str
|
Path to the image file. Recognizes |
required |
imageName |
str
|
Base name for the output cropped sub-images. |
'test_image'
|
markerChannelMapPath |
str
|
Path to a |
None
|
markers |
list
|
A list of marker names indicating which markers to generate single patches for. These should correspond to the names used in the spatial feature matrix. |
['DNA1']
|
markerColumnName |
str
|
The name of the column in the |
'marker'
|
channelColumnName |
str
|
The name of the column in the |
'channel'
|
x_coordinate |
str
|
The column name in the spatial feature matrix that holds the X coordinates. |
'X_centroid'
|
y_coordinate |
str
|
The column name in the spatial feature matrix that holds the Y coordinates. |
'Y_centroid'
|
cell_indicator |
str
|
The column name in the spatial feature matrix that holds the unique cell identifiers. |
'CellID'
|
cropsize |
int
|
The size in pixels for the square crop from each axis centered on the cell coordinates. |
16
|
image_fraction |
float
|
Fraction of the cells to sample and crop, specified as a float between 0.0 and 1.0. |
1
|
random_state |
int
|
Seed for the random number generator used when sampling cells, if |
1
|
verbose |
bool
|
If True, prints detailed process information to the console. |
True
|
projectDir |
string
|
Path to the output directory where results will be saved. If not specified, the current working directory is used. The output will be placed in a subdirectory structure: |
None
|
Returns:
Name | Type | Description |
---|---|---|
Images |
.tif
|
The function saves the list of image patches centered on the coordinates specified in the spatial feature matrix to the specified path. |
Example
import spatialae as sa
# Define paths and parameters
## specify meta_table with cell cooridinates information and image path
## set the projectDir for saving the cropped images
spatialTablePath="D://ResearchData/scimaptutorials/files/meta_data.csv"
imagePath="D://ResearchData/scimaptutorials/files/reactive_core.tif"
projectDir = "D://ResearchData/"
sa.generateSinglePatch(spatialTablePath,imagePath, projectDir = projectDir)
# Generate single patches for multiple markers, specifying a marker-channel map
markerChannelMapPath = "D://ResearchData/SpatialAE/data/markers.csv"
sa.generateSinglePatch(spatialTablePath, imagePath, markerChannelMapPath, markers = ["DNA1", "DNA2"], projectDir = projectDir)
Source code in spatialae/datasets/ppimage.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|