core.MEDIAR.utils
=================

.. py:module:: core.MEDIAR.utils

.. autoapi-nested-parse::

   Copyright © 2022 Howard Hughes Medical Institute,
   Authored by Carsen Stringer and Marius Pachitariu.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are met:

   1. Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.

   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.

   3. Neither the name of HHMI nor the names of its contributors may be used to
      endorse or promote products derived from this software without specific
      prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   POSSIBILITY OF SUCH DAMAGE.

   --------------------------------------------------------------------------
   MEDIAR Prediction uses CellPose's Gradient Flow Tracking.

   This code is adapted from the following codes:
   [1] https://github.com/MouseLand/cellpose/blob/main/cellpose/utils.py
   [2] https://github.com/MouseLand/cellpose/blob/main/cellpose/dynamics.py
   [3] https://github.com/MouseLand/cellpose/blob/main/cellpose/metrics.py







Module Contents
---------------

.. py:data:: torch_GPU

.. py:data:: torch_CPU

.. py:function:: labels_to_flows(labels, use_gpu=False, device=None, redo_flows=False)

   Convert labels (list of masks or flows) to flows for training model


.. py:function:: compute_masks(dP, cellprob, p=None, niter=200, cellprob_threshold=0.4, flow_threshold=0.4, interp=True, resize=None, use_gpu=False, device=None)

   compute masks using dynamics from dP, cellprob, and boundary


.. py:function:: diameters(masks)

.. py:function:: masks_to_flows_gpu(masks, device=None)

.. py:function:: masks_to_flows(masks, use_gpu=False, device=None)

.. py:function:: steps2D_interp(p, dP, niter, use_gpu=False, device=None)

.. py:function:: follow_flows(dP, mask=None, niter=200, interp=True, use_gpu=True, device=None)

.. py:function:: flow_error(maski, dP_net, use_gpu=False, device=None)

.. py:function:: remove_bad_flow_masks(masks, flows, threshold=0.4, use_gpu=False, device=None)

.. py:function:: get_masks(p, iscell=None, rpad=20)

