DeepSNR CLI for macOS arm64 - CoreML Backend
============================================

DeepSNR is a deep-learning-based tool for noise reduction in astronomical
images. This package uses the native CoreML backend and includes the
executable and model packages together.

System requirements: macOS 13.1 or newer on Apple Silicon.

This is the recommended macOS lane for Apple Silicon.

Keep ./deepsnr, DeepSNR_weights_v1.mlpackage, and
DeepSNR_weights_v2.mlpackage together. The executable uses the bundled
weights next to itself by default. Use --model 1 or --model 2 to select a
bundled model; use --weights only to override the bundled model package. Do
not mix files from different DeepSNR packages.

Output paths are resolved relative to the current working directory unless
absolute.

Native Installer
----------------

The macOS .pkg installer is the easiest OS-integrated installation option. It
places deepsnr in /usr/local/bin and the model packages in
/usr/local/lib/deepsnr. After that, deepsnr can be run from any terminal without
manually copying files.

Install-Style Layout
--------------------

Portable archive:
  Extract the archive and run from that directory. Keep the executable,
  model weights, README, and license as shipped.

Manual install:
  To run deepsnr from anywhere, place the files like this:

    /usr/local/bin/deepsnr
    /usr/local/lib/deepsnr/<model weights>

  Package managers can use /usr/bin/deepsnr and /usr/lib/deepsnr/ instead.


Quick Start
-----------

Run the executable from the extracted package directory, or invoke it by
path from another working directory:

  ./deepsnr --input input.tif --output denoised.tif

Model 2 is the default and supports RGB and grayscale images. Model 1 is the
older model line and is intended for RGB images.


Options
-------

  -i, --input <file>
      Input image filename. Required for processing. Recommended: TIFF/TIF, PNG, or supported FITS.

  -o, --output <file>
      Denoised output image filename. Default: denoised.jpg. Use .fit, .fits, or .fts for FITS output; FITS input storage type and scaling are preserved.

  -m, --model <1|2>
      Select bundled model version 1 or 2 from the package directory.
      Default: 2. Model 2 supports RGB and grayscale images. Model 1 is
      the older model line and is intended for RGB images. This option is
      ignored when --weights is provided.

  -w, --weights <file>
      Override the bundled model package. Normally omit this option and use
      --model 1 or --model 2 to select DeepSNR_weights_v1.mlpackage or
      DeepSNR_weights_v2.mlpackage from the package directory.

  -s, --stride <int>
      Tile stride. Default: 480. The value must be even and no larger than
      the 512 pixel processing window.

  --linear
      Apply automatic per-channel MTF to normalized linear input before
      inference, then inverse MTF afterward.
      The inverse step will restore original source samples automatically at every
      position clipped by the forward stretch; there is no separate option.

  --shadows-clipping <number>
      Linear MTF shadows factor in normalized MAD units. Default: -2.80.
      Requires --linear.

  --target-background <number>
      Linear MTF target background between 0 and 1. Default: 0.25.
      Requires --linear.

  -q, --quiet
      Suppress progress output.


  --machine-info
      Print machine-readable product information as JSON and exit.

  --check-updates
      Check the latest CLI version for this platform and exit. Some builds may
      report that update checking is not available.

  --machine-progress
      Print machine-readable progress events as JSON Lines on stderr.


Inputs And Outputs
------------------

Tested input formats are TIFF/TIF, PNG, and supported FITS. TIFF inputs are
tested in uncompressed, LZW, and Deflate variants. JPEG/JPG and BMP might
work through OpenCV, but these formats were not tested for this release. JPEG
is lossy and not recommended for scientific or archival data.

Supported non-FITS input sample depths are 8-bit and 16-bit integer images.
Supported FITS inputs are standard image HDUs in .fit, .fits, .fts, .fit.gz,
.fits.gz, or .fts.gz files,
including 2D grayscale images and simple 3-channel RGB cubes. Integer FITS
inputs are normalized to the internal floating-point range. Float32 and float64
FITS inputs must already contain normalized [0,1] physical samples; otherwise
the CLI reports the observed range and asks the caller to normalize the image.
Arbitrary scientific FITS cubes, FITS tables, and unsupported FITS HDU layouts are rejected.

Model 1 accepts RGB/color images only. Model 2 accepts RGB/color and true
grayscale/monochrome images. Images with alpha channels or other channel counts
are rejected. Images must be at least 512x512 pixels.

Both models work on images from monochrome CCD cameras. Drizzle-integrated
images from one-shot color cameras might work as well. To expect good results,
your noise should be uncorrelated high-frequency noise; correlated noise, such
as walking noise, will yield poor results.

TIFF and PNG outputs preserve 8-bit or 16-bit non-FITS input depth. FITS
inputs converted to TIFF or PNG use 16-bit unsigned integer output. TIFF outputs
are always saved with LZW compression. PNG output uses OpenCV default encoding.
FITS-to-FITS outputs preserve the source storage type and numeric scaling.
FITS output from other input formats uses 32-bit floating-point standard image HDUs.
There is no output-depth option; sample type selection is automatic.

Each FITS output is a new single-image FITS built from the selected supported
image HDU. Applicable nonstructural header cards from that HDU are preserved;
other HDUs and their headers are not copied.
Same-family astronomy metadata is preserved: FITS headers for FITS outputs and
AstroTIFF ImageDescription tag 270 for TIFF outputs. Cross-format metadata
conversion is not performed. Ordinary paths containing spaces and parentheses
are supported when passed as one quoted shell argument.

Legal
-----

The DeepSNR neural-network architecture is based on the NAFNet repository:

  https://github.com/megvii-research/NAFNet

See LICENSE.txt for the DeepSNR license. CFITSIO license information is included with the bundled runtime files. This package uses Apple's system
CoreML framework and does not redistribute CoreML runtime libraries.
