Skip to content

Commit

Permalink
Fix tool
Browse files Browse the repository at this point in the history
  • Loading branch information
kostrykin committed Mar 11, 2024
1 parent 7c2ae17 commit e48ecdf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 6 additions & 4 deletions tools/orientationpy/orientationpy-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
parser.add_argument('--sigma', type=float, required=True)
parser.add_argument('--min_coherency', type=float, required=True)
parser.add_argument('--min_energy', type=float, required=True)
parser.add_argument('--bin_size', type=int, required=True)
parser.add_argument('--bin_size', type=float, required=True)
parser.add_argument('--output_angle_tsv', type=str, default=None)
args = parser.parse_args()

Expand All @@ -24,6 +24,8 @@
im = np.squeeze(im)
assert im.ndim == 2

assert args.bin_size > 0

Gy, Gx = orientationpy.computeGradient(im, mode=args.mode)
structureTensor = orientationpy.computeStructureTensor([Gy, Gx], sigma=args.sigma)
orientations = orientationpy.computeOrientation(structureTensor, computeEnergy=True, computeCoherency=True)
Expand All @@ -39,7 +41,7 @@
angles,
range=(-90, +90),
weights=weights,
bins=180 / args.bin_size,
bins=round(180 / args.bin_size),
)
hidx = np.argmax(hist)
angle = (bin_edges[hidx] + bin_edges[hidx + 1]) / 2
Expand All @@ -48,5 +50,5 @@
if args.output_angle_tsv:
with open(args.output_angle_tsv, 'w') as fp:
writer = csv.writer(fp, delimiter='\t', lineterminator='\n')
writer.writerow('Angle')
writer.writerow(angle)
writer.writerow(['Angle'])
writer.writerow([angle])
10 changes: 8 additions & 2 deletions tools/orientationpy/orientationpy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
--sigma $sigma
--min_energy $min_energy
--min_coherency $min_coherency
--bin_size $bin_size
## Outputs
Expand All @@ -40,36 +41,41 @@
<param argument="--sigma" type="float" label="Spatial scale (in pixels)" value="2" />
<param argument="--min_energy" type="float" label="Minimum energy" value="0.1" min="0" max="1" />
<param argument="--min_coherency" type="float" label="Minimum coherency" value="0.2" min="0" max="1" />
<param argument="--bin_size" type="float" label="Histogram bin size" value="1" min="0" max="1" help="Governs the precision of the estimation (smaller is better). Must be strictly positive." />
</inputs>
<outputs>
<data format="tsv" name="output_angle_tsv" from_work_dir="output_angle.tsv" />
</outputs>
<tests>
<!-- Test negative angle -->
<test>
<param name="image" value="input1.tif" />
<param name="mode" value="finite_difference" />
<param name="sigma" value="2" />
<param name="min_energy" value="0.1" />
<param name="min_coherency" value="0.2" />
<param name="bin_size" value="2" />
<output name="output_angle_tsv">
<assert_contents>
<has_line line="Angle" />
<has_line line="45" />
<has_line line="-44.95" />
<has_n_lines n="2" />
<has_n_columns n="1" />
</assert_contents>
</output>
</test>
<!-- Test positive angle -->
<test>
<param name="image" value="input2.tif" />
<param name="mode" value="finite_difference" />
<param name="sigma" value="2" />
<param name="min_energy" value="0.1" />
<param name="min_coherency" value="0.2" />
<param name="bin_size" value="2" />
<output name="output_angle_tsv">
<assert_contents>
<has_line line="Angle" />
<has_line line="-45" />
<has_line line="45.05" />
<has_n_lines n="2" />
<has_n_columns n="1" />
</assert_contents>
Expand Down

0 comments on commit e48ecdf

Please sign in to comment.