def register(imgs, dots, method = 'translation'): mip_imgs = imgs.reduce(dims = [Axes.CH, Axes.ZPLANE], func="max") mip_dots = dots.reduce(dims = [Axes.CH, Axes.ZPLANE], func="max") learn_translation = LearnTransform.Translation(reference_stack=mip_dots, axes=Axes.ROUND, upsampling=1000) transforms_list = learn_translation.run(mip_imgs) warp = ApplyTransform.Warp() registered_imgs = warp.run(imgs, transforms_list=transforms_list, in_place=False, verbose=True) return registered_imgs
def process_fov(fov: FieldOfView, codebook: Codebook) -> DecodedIntensityTable: """Process a single field of view of ISS data Parameters ---------- fov : FieldOfView the field of view to process codebook : Codebook the Codebook to use for decoding Returns ------- DecodedSpots : tabular object containing the locations of detected spots. """ # note the structure of the 5D tensor containing the raw imaging data imgs = fov.get_image(FieldOfView.PRIMARY_IMAGES) dots = fov.get_image("dots") nuclei = fov.get_image("nuclei") print("Learning Transform") learn_translation = LearnTransform.Translation(reference_stack=dots, axes=Axes.ROUND, upsampling=1000) transforms_list = learn_translation.run( imgs.reduce({Axes.CH, Axes.ZPLANE}, func="max")) print("Applying transform") warp = ApplyTransform.Warp() registered_imgs = warp.run(imgs, transforms_list=transforms_list, verbose=True) print("Filter WhiteTophat") filt = Filter.WhiteTophat(masking_radius=15, is_volume=False) filtered_imgs = filt.run(registered_imgs, verbose=True) filt.run(dots, verbose=True, in_place=True) filt.run(nuclei, verbose=True, in_place=True) print("Detecting") detector = FindSpots.BlobDetector( min_sigma=1, max_sigma=10, num_sigma=30, threshold=0.01, measurement_type='mean', ) dots_max = dots.reduce((Axes.ROUND, Axes.ZPLANE), func="max", module=FunctionSource.np) spots = detector.run(image_stack=filtered_imgs, reference_image=dots_max) print("Decoding") decoder = DecodeSpots.PerRoundMaxChannel(codebook=codebook) decoded = decoder.run(spots=spots) return decoded
def process_fov(field_num: int, experiment_str: str): """Process a single field of view of ISS data Parameters ---------- field_num : int the field of view to process experiment_str : int path of experiment json file Returns ------- DecodedSpots : tabular object containing the locations of detected spots. """ fov_str: str = f"fov_{int(field_num):03d}" # load experiment experiment = starfish.Experiment.from_json(experiment_str) print(f"loading fov: {fov_str}") fov = experiment[fov_str] # note the structure of the 5D tensor containing the raw imaging data imgs = fov.get_image(FieldOfView.PRIMARY_IMAGES) dots = fov.get_image("dots") nuclei = fov.get_image("nuclei") print("Learning Transform") learn_translation = LearnTransform.Translation(reference_stack=dots, axes=Axes.ROUND, upsampling=1000) transforms_list = learn_translation.run(imgs.reduce({Axes.CH, Axes.ZPLANE}, func="max")) print("Applying transform") warp = ApplyTransform.Warp() registered_imgs = warp.run(imgs, transforms_list=transforms_list, in_place=True, verbose=True) print("Filter WhiteTophat") filt = Filter.WhiteTophat(masking_radius=15, is_volume=False) filtered_imgs = filt.run(registered_imgs, verbose=True, in_place=True) filt.run(dots, verbose=True, in_place=True) filt.run(nuclei, verbose=True, in_place=True) print("Detecting") detector = DetectSpots.BlobDetector( min_sigma=1, max_sigma=10, num_sigma=30, threshold=0.01, measurement_type='mean', ) intensities = detector.run(filtered_imgs, blobs_image=dots, blobs_axes=(Axes.ROUND, Axes.ZPLANE)) decoded = experiment.codebook.decode_per_round_max(intensities) df = decoded.to_decoded_dataframe() return df
def iss_pipeline(fov, codebook): primary_image = fov.get_image(starfish.FieldOfView.PRIMARY_IMAGES) # register the raw image learn_translation = LearnTransform.Translation( reference_stack=fov.get_image('dots'), axes=Axes.ROUND, upsampling=100) transforms_list = learn_translation.run( primary_image.reduce({Axes.CH, Axes.ZPLANE}, func="max")) warp = ApplyTransform.Warp() registered = warp.run(primary_image, transforms_list=transforms_list, in_place=False, verbose=True) # filter raw data masking_radius = 15 filt = Filter.WhiteTophat(masking_radius, is_volume=False) filtered = filt.run(registered, verbose=True, in_place=False) bd = FindSpots.BlobDetector( min_sigma=1, max_sigma=10, num_sigma=30, threshold=0.01, measurement_type='mean', ) # detect spots using laplacian of gaussians approach dots_max = fov.get_image('dots').reduce((Axes.ROUND, Axes.ZPLANE), func="max", module=FunctionSource.np) # locate spots in a reference image spots = bd.run(reference_image=dots_max, image_stack=filtered) # decode the pixel traces using the codebook decoder = DecodeSpots.PerRoundMaxChannel(codebook=codebook) decoded = decoder.run(spots=spots) # segment cells seg = Segment.Watershed( nuclei_threshold=.16, input_threshold=.22, min_distance=57, ) label_image = seg.run(primary_image, fov.get_image('dots')) # assign spots to cells ta = AssignTargets.Label() assigned = ta.run(label_image, decoded) return assigned, label_image
def iss_pipeline(fov, codebook): primary_image = fov.get_image(starfish.FieldOfView.PRIMARY_IMAGES) # register the raw image learn_translation = LearnTransform.Translation( reference_stack=fov.get_image('dots'), axes=Axes.ROUND, upsampling=100) max_projector = Filter.Reduce((Axes.CH, Axes.ZPLANE), func="max", module=Filter.Reduce.FunctionSource.np) transforms_list = learn_translation.run(max_projector.run(primary_image)) warp = ApplyTransform.Warp() registered = warp.run(primary_image, transforms_list=transforms_list, in_place=False, verbose=True) # filter raw data masking_radius = 15 filt = Filter.WhiteTophat(masking_radius, is_volume=False) filtered = filt.run(registered, verbose=True, in_place=False) # detect spots using laplacian of gaussians approach p = DetectSpots.BlobDetector( min_sigma=1, max_sigma=10, num_sigma=30, threshold=0.01, measurement_type='mean', ) intensities = p.run(filtered, blobs_image=fov.get_image('dots'), blobs_axes=(Axes.ROUND, Axes.ZPLANE)) # decode the pixel traces using the codebook decoded = codebook.decode_per_round_max(intensities) # segment cells seg = Segment.Watershed( nuclei_threshold=.16, input_threshold=.22, min_distance=57, ) label_image = seg.run(primary_image, fov.get_image('dots')) # assign spots to cells ta = AssignTargets.Label() assigned = ta.run(label_image, decoded) return assigned, label_image
from starfish import data, FieldOfView from starfish.spots import FindSpots experiment = data.ISS() fov = experiment.fov() imgs = fov.get_image(FieldOfView.PRIMARY_IMAGES) # primary images dots = fov.get_image("dots") # reference round for image registration # filter raw data masking_radius = 15 filt = Filter.WhiteTophat(masking_radius, is_volume=False) filt.run(imgs, in_place=True) filt.run(dots, in_place=True) # register primary images to reference round learn_translation = LearnTransform.Translation(reference_stack=dots, axes=Axes.ROUND, upsampling=1000) transforms_list = learn_translation.run( imgs.reduce({Axes.CH, Axes.ZPLANE}, func="max")) warp = ApplyTransform.Warp() warp.run(imgs, transforms_list=transforms_list, in_place=True) # run blob detector on dots (reference image with every spot) bd = FindSpots.BlobDetector( min_sigma=1, max_sigma=10, num_sigma=30, threshold=0.01, measurement_type='mean', ) dots_max = dots.reduce((Axes.ROUND, Axes.ZPLANE), func="max")
# load STARmap data from starfish import data, display from starfish.image import ApplyTransform, LearnTransform from starfish.spots import FindSpots from starfish.types import Axes from starfish.util.plot import imshow_plane from starfish.core.spots.DecodeSpots.trace_builders import build_spot_traces_exact_match experiment = data.STARmap(use_test_data=True) imgs = experiment['fov_000'].get_image('primary') # register rounds projection = imgs.reduce({Axes.CH, Axes.ZPLANE}, func="max") reference_image = projection.sel({Axes.ROUND: 0}) ltt = LearnTransform.Translation(reference_stack=reference_image, axes=Axes.ROUND, upsampling=1000) transforms = ltt.run(projection) warp = ApplyTransform.Warp() imgs = warp.run(stack=imgs, transforms_list=transforms) # make reference round for decoding dots = imgs.reduce({Axes.CH, Axes.ROUND}, func="max") # view a cropped region of image for spot finding imshow_plane(dots, sel={ Axes.ZPLANE: 15, Axes.X: (400, 600), Axes.Y: (400, 600) })