Skip to content

Commit

Permalink
Add workaround for TIFF dimension issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kostrykin committed Sep 24, 2024
1 parent ee45ab5 commit bc288c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
17 changes: 15 additions & 2 deletions tools/spot_detection_2d/spot_detection_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import numpy as np
import pandas as pd
import scipy.ndimage as ndi
import tifffile
from numpy.typing import NDArray
from skimage.feature import blob_dog, blob_doh, blob_log

Expand All @@ -36,6 +37,18 @@ def mean_intensity(img: NDArray, y: int, x: int, radius: int) -> float:
return img[mask].mean()


def load_image(fn_in: str) -> NDArray:
"""
Load the input image using ``tifffile`` if possible.
This is necessary to properly load multi-page TIFF files.
"""
try:
return giatools.io.imread(fn_in, impl=tifffile.imread)
except tifffile.TiffFileError:
return giatools.io.imread(fn_in) # Not a TIFF file


def spot_detection(
fn_in: str,
fn_out: str,
Expand All @@ -50,7 +63,7 @@ def spot_detection(
) -> None:

# Load the single-channel 2-D input image (or stack thereof)
stack = giatools.io.imread(fn_in)
stack = load_image(fn_in)

# Normalize input image so that it is a stack of images (possibly a stack of a single image)
assert stack.ndim in (2, 3)
Expand Down Expand Up @@ -96,7 +109,7 @@ def spot_detection(

parser = argparse.ArgumentParser(description="Spot detection")

parser.add_argument("fn_in", help="Name of input image or image sequence (stack).")
parser.add_argument("fn_in", help="Name of input image or image stack.")
parser.add_argument("fn_out", help="Name of output file to write the detections into.")
parser.add_argument("frame_1st", type=int, help="Index for the starting frame to detect spots (1 for first frame of the stack).")
parser.add_argument("frame_end", type=int, help="Index for the last frame to detect spots (0 for the last frame of the stack).")
Expand Down
7 changes: 4 additions & 3 deletions tools/spot_detection_2d/spot_detection_2d.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tool id="ip_spot_detection_2d" name="Perform 2-D spot detection" version="0.1" profile="20.05">
<tool id="ip_spot_detection_2d" name="Perform 2-D spot detection" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.05">
<description></description>
<macros>
<import>creators.xml</import>
Expand All @@ -19,6 +19,7 @@
<requirement type="package" version="1.26.4">numpy</requirement>
<requirement type="package" version="1.2.4">pandas</requirement>
<requirement type="package" version="0.21">scikit-image</requirement>
<requirement type="package" version="2024.6.18">tifffile</requirement>
</requirements>
<command detect_errors="aggressive">
<![CDATA[
Expand All @@ -36,7 +37,7 @@
]]>
</command>
<inputs>
<param name="fn_in" type="data" format="tiff" label="Intensity image or image sequence (stack)" />
<param name="fn_in" type="data" format="tiff" label="Intensity image or a stack of images" />
<param name="frame_1st" type="integer" value="1" label="Starting time point (1 for the first frame of the stack)" />
<param name="frame_end" type="integer" value="0" label="Ending time point (0 for the last frame of the stack)" />
<param name="filter_type" type="select" label="Detection filter">
Expand Down Expand Up @@ -85,7 +86,7 @@

**Perform spot detection and measure the image intensities.**

This tool detects spots (blobs) and measures the image intensities in a single-channel 2-D image (or sequence thereof).
This tool detects spots (blobs) and measures the image intensities in a single-channel 2-D image (or a stack of such images).

The tool produces a TSV file containing all detections, with the following columns:

Expand Down

0 comments on commit bc288c4

Please sign in to comment.