<commit_before># Copyright 2012 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================

# ============= enthought library imports =======================
from traits.api import Float
# ============= standard library imports ========================
from numpy import array, histogram, argmax, zeros, asarray, ones_like, \
    nonzero, max, arange, argsort, invert
from skimage.feature import peak_local_max
from skimage.transform import hough_circle
from skimage.morphology import watershed
from skimage.draw import polygon, circle, circle_perimeter, circle_perimeter_aa
from scipy import ndimage
from skimage.exposure import rescale_intensity
from skimage.filters import gaussian_filter
from skimage import feature
from skimage.feature import canny
# ============= local library imports  ==========================
# from pychron.core.geometry.centroid.calculate_centroid import calculate_centroid
from pychron.loggable import Loggable
from pychron.mv.segment.region import RegionSegmenter
from pychron.image.cv_wrapper import grayspace, draw_contour_list, contour, \
    colorspace, get_polygons, get_size, new_point, draw_rectangle, \
    draw_lines, \
    draw_polygons, crop
from pychron.mv.target import Target
# from pychron.image.image import StandAloneImage
from pychron.core.geometry.geometry import approximate_polygon_center, \
    calc_length


# from scipy.interpolate.ndgriddata import griddata


# def debug_show(image, distance, wsrc, nimage=None):
#     from pylab import subplots, show, subplots_adjust, cm
# #     import matplotlib.pyplot as plt
#     print 'asdsdaf'
#     fig, axes = subplots(ncols=4, figsize=(8, 2.7))
#     ax0, ax1, ax2, ax3 = axes
#
#     ax0.imshow(image, cmap=cm.gray, interpolation='nearest')
#     ax1.imshow(-distance, cmap=cm.jet, interpolation='nearest')
#     ax2.imshow(wsrc, cmap=cm.jet,
#                 interpolation='nearest'
#                )
#     if nimage is not None:
#         ax3.imshow(nimage, cmap=cm.jet,
# #                    interpolation='nearest'
#                    )
#
# #     for ax in axes:
# #         ax.axis('off')
#
# #     subplots_adjust(hspace=0.01, wspace=0.01, top=1, bottom=0, left=0,
# #                     right=1)
#     invoke_in_main_thread(show)
def draw_circle(frame, center_x, center_y, radius, color, **kw):
    cx, cy = circle(int(center_x), int(center_y), int(radius))
    frame[cy, cx] = color


def draw_circle_perimeter(frame, center_x, center_y, radius, color):
    cx, cy = circle_perimeter(int(center_x), int(center_y), int(radius))
    frame[cy, cx] = color


class Locator(Loggable):
    pxpermm = Float
    use_histogram = False
    use_circle_minimization = True
    step_signal = None

    def wait(self):
        if self.step_signal:
            self.step_signal.wait()
            self.step_signal.clear()

    def crop(self, src, cw, ch, ox=0, oy=0, verbose=True):

        cw_px = int(cw * self.pxpermm)
        ch_px = int(ch * self.pxpermm)
        w, h = get_size(src)

        x = int((w - cw_px) / 2. + ox)
        y = int((h - ch_px) / 2. - oy)

        # r = 4 - cw_px % 4
        # cw_px = ch_px = cw_px + r
        if verbose:
            self.debug('Crop: x={},y={}, cw={}, ch={}, '
                       'width={}, height={}, ox={}, oy={}'.format(x, y, cw_px, ch_px, w, h, ox, oy))
        return asarray(crop(src, x, y, cw_px, ch_px))

    def find_circle(self, image, frame, dim, **kw):<commit_msg>fixed drawing circle during autocenter<commit_after># Copyright 2012 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================

# ============= enthought library imports =======================
from traits.api import Float
# ============= standard library imports ========================
from numpy import array, histogram, argmax, zeros, asarray, ones_like, \
    nonzero, max, arange, argsort, invert
from skimage.feature import peak_local_max
from skimage.transform import hough_circle
from skimage.morphology import watershed
from skimage.draw import polygon, circle, circle_perimeter, circle_perimeter_aa
from scipy import ndimage
from skimage.exposure import rescale_intensity
from skimage.filters import gaussian_filter
from skimage import feature
from skimage.feature import canny
# ============= local library imports  ==========================
# from pychron.core.geometry.centroid.calculate_centroid import calculate_centroid
from pychron.loggable import Loggable
from pychron.mv.segment.region import RegionSegmenter
from pychron.image.cv_wrapper import grayspace, draw_contour_list, contour, \
    colorspace, get_polygons, get_size, new_point, draw_rectangle, \
    draw_lines, \
    draw_polygons, crop
from pychron.mv.target import Target
# from pychron.image.image import StandAloneImage
from pychron.core.geometry.geometry import approximate_polygon_center, \
    calc_length


def _coords_inside_image(rr, cc, shape):
    mask = (rr >= 0) & (rr < shape[0]) & (cc >= 0) & (cc < shape[1])
    return rr[mask], cc[mask]


def draw_circle(frame, center_x, center_y, radius, color, **kw):
    cy, cx = circle(int(center_y), int(center_x), int(radius), shape=frame.shape)
    frame[cy, cx] = color


def draw_circle_perimeter(frame, center_x, center_y, radius, color):
    cy, cx = circle_perimeter(int(center_y), int(center_x), int(radius))

    cy, cx = _coords_inside_image(cy, cx, frame.shape)
    frame[cy, cx] = color


class Locator(Loggable):
    pxpermm = Float
    use_histogram = False
    use_circle_minimization = True
    step_signal = None

    def wait(self):
        if self.step_signal:
            self.step_signal.wait()
            self.step_signal.clear()

    def crop(self, src, cw, ch, ox=0, oy=0, verbose=True):

        cw_px = int(cw * self.pxpermm)
        ch_px = int(ch * self.pxpermm)
        w, h = get_size(src)

        x = int((w - cw_px) / 2. + ox)
        y = int((h - ch_px) / 2. - oy)

        # r = 4 - cw_px % 4
        # cw_px = ch_px = cw_px + r
        if verbose:
            self.debug('Crop: x={},y={}, cw={}, ch={}, '
                       'width={}, height={}, ox={}, oy={}'.format(x, y, cw_px, ch_px, w, h, ox, oy))
        return asarray(crop(src, x, y, cw_px, ch_px))

    def find_circle(self, image, frame, dim, **kw):
{'fraction_non_alphanumeric': 0.15323018458197613, 'fraction_numerical': 0.007328990228013029, 'mean_word_length': 3.649211356466877, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1318891', 'n_tokens_mistral': 2406, 'n_tokens_neox': 2301, 'n_words': 678}