Skip to content

Add filter needles#180

Open
Raytesnel wants to merge 6 commits intomainfrom
add-filter_needles
Open

Add filter needles#180
Raytesnel wants to merge 6 commits intomainfrom
add-filter_needles

Conversation

@Raytesnel
Copy link
Collaborator

@Raytesnel Raytesnel commented Mar 11, 2026

Adds Filters:
- FilterNeedles
- FilterMedian
These two are used in rotation.py
I shuffeled the order a bit around to extract some logic like if No bounding_box is given then we dont need to rotate, but only crop and mask. by reordening i could extract that piece in put it in the controller.py. so we don't call a rotate function without the need for rotation. tests that were only cropping and masking not rotating are deleted. because we already coverd those tests and extrected that usecase.

things i like to fix but didnt (yet).
i would like to extract CropToMask from the rotate_crop_and_mask_image_by_crop so we could have a pure Rotation function. and create the pipeline without hiding buisness logic.
stuff like making the margin bigger when rotation would be ideal to put it in the controller and not inside the execution.

@Raytesnel Raytesnel requested a review from SimoneAriens March 11, 2026 11:47
@Raytesnel Raytesnel self-assigned this Mar 11, 2026
@Raytesnel Raytesnel changed the base branch from main to add-rotate-mutation March 11, 2026 11:47
Base automatically changed from add-rotate-mutation to main March 11, 2026 12:05
@Raytesnel Raytesnel force-pushed the add-filter_needles branch from 8aa66b4 to b98e218 Compare March 13, 2026 10:05
@Raytesnel Raytesnel force-pushed the add-filter_needles branch from b98e218 to bb4c53f Compare March 13, 2026 10:29
With the same scan_file the loader due to caching gave back a mutable ScanImage. Moved caching to only the load Surface from scan-file, but makes every load a new ScanImage object.
@Raytesnel Raytesnel force-pushed the add-filter_needles branch from 409d83c to e3485c2 Compare March 13, 2026 12:17
@Raytesnel Raytesnel marked this pull request as ready for review March 13, 2026 12:19
@github-actions
Copy link

Diff Coverage

Diff: origin/main..HEAD, staged and unstaged changes

  • packages/scratch-core/src/computations/spatial.py (81.8%): Missing lines 23,25
  • packages/scratch-core/src/conversion/rotate.py (100%)
  • packages/scratch-core/src/mutations/filter.py (100%)
  • packages/scratch-core/src/mutations/spatial.py (100%)
  • packages/scratch-core/src/parsers/loaders.py (100%)
  • src/preprocessors/controller.py (50.0%): Missing lines 33-36

Summary

  • Total: 99 lines
  • Missing: 6 lines
  • Coverage: 93%

packages/scratch-core/src/computations/spatial.py

Lines 19-28

  19     x_min = max(0, x_coords.min() + margin)
  20     x_max = min(mask.shape[1], x_coords.max() - margin + 1)
  21 
  22     if x_min >= x_max:
! 23         raise ValueError("Slice results in x_min >= x_max. Margin may be too large.")
  24     if y_min >= y_max:
! 25         raise ValueError("Slice results in y_min >= y_max. Margin may be too large.")
  26 
  27     return slice(y_min, y_max), slice(x_min, x_max)

src/preprocessors/controller.py

Lines 29-40

  29     scan_image: ScanImage, mark_type: MarkType, mask: BinaryMask, bounding_box: BoundingBox | None
  30 ) -> Mark:
  31     """Parse a scan file and extract a mark by rotating, cropping, masking, and resampling."""
  32     if bounding_box is None:
! 33         logger.info("Masking and Cropping scan image")
! 34         scan_image_masked = Mask(mask=mask)(scan_image).unwrap()
! 35         scan_image_cleaned = FilterNeedles()(scan_image_masked).unwrap()
! 36         rotated_image = CropToMask(mask=mask)(scan_image_cleaned).unwrap()
  37     else:
  38         logger.info("Rotating Masking and Cropping scan image")
  39         rotated_image = rotate_crop_and_mask_image_by_crop(scan_image=scan_image, mask=mask, bounding_box=bounding_box)
  40     logger.info("Transforming scan image to mark")

@github-actions
Copy link

Code Coverage

Package Line Rate Branch Rate Health
. 96% 88%
comparators 100% 100%
computations 85% 50%
container_models 99% 100%
conversion 95% 78%
conversion.export 100% 100%
conversion.filter 97% 89%
conversion.leveling 100% 100%
conversion.leveling.solver 100% 75%
conversion.plots 98% 88%
conversion.preprocess_impression 99% 91%
conversion.preprocess_striation 89% 58%
conversion.profile_correlator 96% 82%
conversion.surface_comparison 96% 88%
conversion.surface_comparison.cell_registration 100% 100%
extractors 99% 75%
mutations 100% 100%
parsers 98% 80%
parsers.patches 89% 60%
preprocessors 97% 85%
processors 99% 100%
renders 98% 67%
utils 92% 75%
Summary 97% (3325 / 3421) 84% (358 / 426)

Minimum allowed line rate is 50%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant