Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grabseeds #649

Merged
merged 4 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
strategy:
max-parallel: 4
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-13]
python-version: ["3.8", "3.10"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
Expand All @@ -26,7 +26,7 @@ jobs:

- name: Install BEDTools (macOS)
run: brew install bedtools
if: matrix.os == 'macos-latest'
if: matrix.os == 'macos-13'

- name: Install dependencies
run: |
Expand Down
14 changes: 9 additions & 5 deletions jcvi/graphics/grabseeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(
seedno: int,
rgb: RGBTuple,
props: Any,
efds: np.ndarray,
exif: dict,
):
self.imagename = imagename
Expand All @@ -81,6 +82,7 @@ def __init__(
self.length = int(round(props.major_axis_length))
self.width = int(round(props.minor_axis_length))
self.props = props
self.efds = efds
self.circularity = 4 * pi * props.area / props.perimeter**2
self.rgb = rgb
self.colorname = closest_color(rgb)
Expand Down Expand Up @@ -113,6 +115,7 @@ def __str__(self):
self.correctedcolorname,
self.correctedrgb,
]
fields += [",".join(f"{x:.3f}" for x in self.efds)]
return "\t".join(str(x) for x in fields)

@classmethod
Expand All @@ -129,6 +132,7 @@ def header(cls, calibrated: bool = False) -> str:
"PixelCMratio RGBtransform Length(cm)"
" Width(cm) CorrectedColorName CorrectedRGB".split()
)
fields += ["EllipticFourierDescriptors"]
return "\t".join(fields)

def calibrate(self, pixel_cm_ratio: float, tr: np.ndarray):
Expand Down Expand Up @@ -585,13 +589,14 @@ def extract_label(labelfile: str) -> str:
return accession


def efd_feature(contour: np.ndarray, order: int = 20) -> np.ndarray:
def efd_feature(contour: np.ndarray) -> np.ndarray:
"""
To use EFD as features, one can write a small wrapper function.

Based on: https://pyefd.readthedocs.io/en/latest
"""
coeffs = elliptic_fourier_descriptors(contour, order=order, normalize=True)
coeffs = elliptic_fourier_descriptors(contour, normalize=True)
# skip the first three coefficients, which are always 1, 0, 0
return coeffs.flatten()[3:]


Expand Down Expand Up @@ -713,8 +718,7 @@ def seeds(args):
break

contour = find_contours(labels == props.label, 0.5)[0]
# TODO: Use EFD as features
_ = efd_feature(contour)
efds = efd_feature(contour)
y0, x0 = props.centroid
orientation = props.orientation
major, minor = props.major_axis_length, props.minor_axis_length
Expand Down Expand Up @@ -743,7 +747,7 @@ def seeds(args):
)

rgb = pixel_stats(pixels)
objects.append(Seed(filename, accession, i, rgb, props, exif))
objects.append(Seed(filename, accession, i, rgb, props, efds, exif))
minr, minc, maxr, maxc = props.bbox
rect = Rectangle(
(minc, minr), maxc - minc, maxr - minr, fill=False, ec="w", lw=1
Expand Down