Generate 3D patches
Short Description
The generateSingle3DCube
function cut out a fixed-size image from the center of a specified, pre-segmented single cell. The cuttted sub-images will be used to train a deep learning model. Make sure to have the raw image, computed single-cell spatial table, and markers.csv file ready for input.
Function¶
generateSingle3DCube(spatialTablePath, imagePath, imageName='test_image', markerChannelMapPath=None, markers=['DNA1'], markerColumnName='marker', channelColumnName='channel', x_coordinate='X_centroid', y_coordinate='Y_centroid', z_coordinate='Z_centroid', cell_indicator='cellID', cropsize=75, z_cropsize=75, padding=True, 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. |
required |
imagePath |
str
|
Path to the image file. Recognizes |
required |
imageName |
str
|
image name for cropped sub images. |
'test_image'
|
markerChannelMapPath |
str
|
Path to a |
None
|
markers |
list
|
Markers for which |
['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 |
'X_centroid'
|
y_coordinate |
str
|
The column name in |
'Y_centroid'
|
z_coordinate |
str
|
The column name in |
'Z_centroid'
|
cell_indicator |
str
|
The column name in |
'cellID'
|
cropsize |
int
|
Default use 75 pixel for x,y. |
75
|
z_cropsize |
int
|
Default use 75 pixel for z. |
75
|
padding |
bool
|
If True, padding the cube to the expected cropsize. Else, filter the cubes without the expected cropsize. |
True
|
image_fraction |
float
|
Percentage of the cells to be cropped and saved.
Default use 100% and crop all cells provided in the |
1
|
random_state |
int
|
random seeds set in sampling the cells to be cropped if image_fraction less than 100%. |
1
|
verbose |
bool
|
If True, print detailed information about the process to the console. |
True
|
projectDir |
string
|
Path to output directory. The result will be located at
|
None
|
Returns:
Name | Type | Description |
---|---|---|
images |
.tif
|
3D cubes will be returned, |
Example
import spatialae
## crop DNA1 channel
spatialTablePath="/home/roh6824/ResearchProject/SpatialMolecular/3D/LSP13626_F8iic_metadata.csv"
imagePath="/n/scratch/users/r/xxx/data/LSP13626/Dataset1-LSP13626-invasive_margin.tif"
# marker = pd.read_table(markerChannelMapPath)
projectDir="/n/scratch/users/r/xxx/Results/LSP13626_DNA_padding/"
spatialae.datasets.generateSingle3DCube(spatialTablePath,
imagePath,
imageName = "LSP13626_3Dimage",
markers = ["DNA1"],
cropsize = 75,
z_cropsize = 75,
padding = True,
cell_indicator="CellID",
image_fraction = 1,
projectDir=projectDir)
## crop multiple channels
markerChannelMapPath="/n/scratch/users/r/roh6824/data/LSP13626/markers.csv"
projectDir="/n/scratch/users/r/roh6824/Results/LSP13626_DNA_padding/"
spatialae.datasets.generateSingle3DCube(spatialTablePath,
imagePath,
imageName = "LSP13626_3Dimage",
markerChannelMapPath = markerChannelMapPath,
markers = ["MART-1", "SOX10", "S100B", "Cytokeratin (pan)"],
cropsize = 75,
z_cropsize = 75,
padding = True,
cell_indicator="CellID",
image_fraction = 1,
projectDir=projectDir)
Source code in spatialae/datasets/pp3dimage.py
26 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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|