Skip to content

Commit

Permalink
Migrate tests to image_diff
Browse files Browse the repository at this point in the history
  • Loading branch information
kostrykin committed Sep 24, 2024
1 parent c5441d8 commit 44ccfb9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
12 changes: 6 additions & 6 deletions tools/points2binaryimage/points2binaryimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import skimage.io


def points2binaryimage(point_file, out_file, shape=[500, 500], has_header=False, invert_xy=False):
def points2binaryimage(point_file, out_file, shape=[500, 500], has_header=False, swap_xy=False):

img = np.zeros(shape, dtype=np.int16)
if os.path.exists(point_file) and os.path.getsize(point_file) > 0:
Expand All @@ -21,7 +21,7 @@ def points2binaryimage(point_file, out_file, shape=[500, 500], has_header=False,
if int(a_row[0]) < 0 or int(a_row[1]) < 0:
raise IndexError("Point {},{} is out of image with bounds {},{}.".format(int(a_row[0]), int(a_row[1]), shape[0], shape[1]))

if invert_xy:
if swap_xy:
if img.shape[0] <= int(a_row[0]) or img.shape[1] <= int(a_row[1]):
raise IndexError("Point {},{} is out of image with bounds {},{}.".format(int(a_row[0]), int(a_row[1]), shape[0], shape[1]))
else:
Expand All @@ -41,14 +41,14 @@ def points2binaryimage(point_file, out_file, shape=[500, 500], has_header=False,

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('point_file', type=argparse.FileType('r'), help='label file')
parser.add_argument('point_file', type=argparse.FileType('r'), help='point file')
parser.add_argument('out_file', type=str, help='out file (TIFF)')
parser.add_argument('shapex', type=int, help='shapex')
parser.add_argument('shapey', type=int, help='shapey')
parser.add_argument('--has_header', dest='has_header', default=False, help='set True if CSV has header')
parser.add_argument('--invert_xy', dest='invert_xy', default=False, help='invert x and y in CSV')
parser.add_argument('--has_header', dest='has_header', default=False, help='set True if point file has header')
parser.add_argument('--swap_xy', dest='swap_xy', default=False, help='Swap X and Y coordinates')

args = parser.parse_args()

# TOOL
points2binaryimage(args.point_file.name, args.out_file, [args.shapey, args.shapex], has_header=args.has_header, invert_xy=args.invert_xy)
points2binaryimage(args.point_file.name, args.out_file, [args.shapey, args.shapex], has_header=args.has_header, swap_xy=args.swap_xy)
29 changes: 18 additions & 11 deletions tools/points2binaryimage/points2binaryimage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<description></description>
<macros>
<import>creators.xml</import>
<import>tests.xml</import>
<token name="@TOOL_VERSION@">0.2</token>
<token name="@VERSION_SUFFIX@">3</token>
</macros>
Expand All @@ -20,17 +21,23 @@
<requirement type="package" version="1.2.4">pandas</requirement>
<requirement type="package" version="2024.6.18">tifffile</requirement>
</requirements>
<command detect_errors="aggressive">
<![CDATA[
python '$__tool_directory__/points2binaryimage.py' '$input' '$output' $shapex $shapey $has_header $invert_xy
]]>
</command>
<command detect_errors="aggressive"><![CDATA[
python '$__tool_directory__/points2binaryimage.py'
'$input'
'$output'
$shapex
$shapey
$has_header
$swap_xy
]]></command>
<inputs>
<param name="input" type="data" format="tabular" label="Tabular point file"/>
<param name="shapex" type="integer" value="500" optional="true" min="1" max="2000" label="Width of output image" />
<param name="shapey" type="integer" value="500" optional="true" min="1" max="2000" label="Height of output image" />
<param name="has_header" type="boolean" checked="false" truevalue="--has_header True" falsevalue="" optional="true" label="Does point file contain header?" />
<param name="invert_xy" type="boolean" checked="false" falsevalue="" truevalue="--invert_xy True" optional="true" label="Inverts x and y in tabular point file" />
<param name="shapex" type="integer" value="500" min="1" label="Width of output image" />
<param name="shapey" type="integer" value="500" min="1" label="Height of output image" />
<param name="has_header" type="boolean" checked="false" truevalue="--has_header True" falsevalue="" optional="true" label="Tabular point file has header" />
<param name="swap_xy" type="boolean" checked="false" falsevalue="" truevalue="--swap_xy True" optional="true" label="Swap X and Y coordinates" />
</inputs>
<outputs>
<data name="output" format="tiff" />
Expand All @@ -42,8 +49,8 @@
<param name="shapex" value="20" />
<param name="shapey" value="30" />
<param name="has_header" value="false" />
<param name="invert_xy" value="true" />
<output name="output" ftype="tiff" file="output1.tif" compare="sim_size"/>
<param name="swap_xy" value="true" />
<expand macro="tests/binary_image_diff" name="output" value="output1.tif" ftype="tiff" />
</test>
<!-- TSV with header -->
</tests>
Expand Down
1 change: 1 addition & 0 deletions tools/points2binaryimage/tests.xml

0 comments on commit 44ccfb9

Please sign in to comment.