Image for :meth:`.curve.Curve.elevate` docstring.
511258
def curve_elevate(curve, elevated):
    """"""
    if NO_IMAGES:
        return

    figure, (ax1, ax2) = plt.subplots(1, 2)
    curve.plot(256, ax=ax1)
    color = ax1.lines[-1].get_color()
    add_patch(ax1, curve._nodes, color)
    elevated.plot(256, ax=ax2)
    color = ax2.lines[-1].get_color()
    add_patch(ax2, elevated._nodes, color)
    ax1.axis("scaled")
    ax2.axis("scaled")
    _plot_helpers.add_plot_boundary(ax1)
    ax2.set_xlim(*ax1.get_xlim())
    ax2.set_ylim(*ax1.get_ylim())
    save_image(figure, "curve_elevate.png")
534766
def ccmod_ystep():
    

    mAXU = np.mean(mp_D_X + mp_D_U, axis=0)
    mp_D_Y[:] = mp_dprox(mAXU)
1276242
def get_data(img_path):
    
    mean = np.array([123.68, 116.779, 103.939])  # (R,G,B)
    img = Image.open(img_path)
    img = np.array(img, dtype=np.float32)
    reshaped_mean = mean.reshape(1, 1, 3)
    img = img - reshaped_mean
    img = np.swapaxes(img, 0, 2)
    img = np.swapaxes(img, 1, 2)
    img = np.expand_dims(img, axis=0)
    return img
56356
def topng(images, path, prefix="image", overwrite=False, credentials=None):
    
    value_shape = images.value_shape
    if not len(value_shape) in [2, 3]:
        raise ValueError("Only 2D or 3D images can be exported to png, "
                         "images are %d-dimensional." % len(value_shape))

    from scipy.misc import imsave
    from io import BytesIO
    from thunder.writers import get_parallel_writer

    def tobuffer(kv):
        key, img = kv
        fname = prefix+"-"+"%05d.png" % int(key)
        bytebuf = BytesIO()
        imsave(bytebuf, img, format='PNG')
        return fname, bytebuf.getvalue()

    writer = get_parallel_writer(path)(path, overwrite=overwrite, credentials=credentials)
    images.foreach(lambda x: writer.write(tobuffer(x)))
149717
def curve_to(self, x, y, x2, y2, x3, y3):
        """"""
        self._add_instruction("curve_to", x, y, x2, y2, x3, y3)
136373
def _generate_example(self, data_path, image_id):
    """"""
    image_filepath = os.path.join(
        data_path, "VOCdevkit/VOC2007/JPEGImages", "{}.jpg".format(image_id))
    annon_filepath = os.path.join(
        data_path, "VOCdevkit/VOC2007/Annotations", "{}.xml".format(image_id))

    def _get_example_objects():
      """Function to get all the objects from the annotation XML file."""
      with tf.io.gfile.GFile(annon_filepath, "r") as f:
        root = xml.etree.ElementTree.parse(f).getroot()

        size = root.find("size")
        width = float(size.find("width").text)
        height = float(size.find("height").text)

        for obj in root.findall("object"):
          # Get object's label name.
          label = obj.find("name").text.lower()
          # Get objects' pose name.
          pose = obj.find("pose").text.lower()
          is_truncated = (obj.find("truncated").text == "1")
          is_difficult = (obj.find("difficult").text == "1")
          bndbox = obj.find("bndbox")
          xmax = float(bndbox.find("xmax").text)
          xmin = float(bndbox.find("xmin").text)
          ymax = float(bndbox.find("ymax").text)
          ymin = float(bndbox.find("ymin").text)
          yield {
              "label": label,
              "pose": pose,
              "bbox": tfds.features.BBox(
                  ymin / height, xmin / width, ymax / height, xmax / width),
              "is_truncated": is_truncated,
              "is_difficult": is_difficult,
          }

    objects = list(_get_example_objects())
    # Use set() to remove duplicates
    labels = sorted(set(obj["label"] for obj in objects))
    labels_no_difficult = sorted(set(
        obj["label"] for obj in objects if obj["is_difficult"] == 0
    ))
    return {
        "image": image_filepath,
        "image/filename": image_id + ".jpg",
        "objects": objects,
        "labels": labels,
        "labels_no_difficult": labels_no_difficult,
    }
1264068
def raise_figure_window(f=0):
    
    if _fun.is_a_number(f): f = _pylab.figure(f)
    f.canvas.manager.window.raise_()
539873
def imagesc(data, title=None, fig='current', ax=None):
  ''''''
  ax = _get_axis(fig, ax, False)
  ax.imshow(data, interpolation='nearest', aspect='auto')
  if title:
    ax.set_title(title)
  return plt.show
991639
def _image_loop(self):
        """"""
        if self.progress_bar and 'tqdm' in self.progress_bar.lower():
            return tqdm(self.imgs, desc='Saving PNGs as flat PDFs', total=len(self.imgs), unit='PDFs')
        else:
            return self.imgs
640274
def step(self):
        """"""
        # Assign attributes to local variables for convenience.
        u = self._u
        
        if u is None:
            raise ValueError("the levelset function is not set "
                             "(use set_levelset)")
        
        data = self.data
        
        # Determine c0 and c1.
        inside = (u > 0)
        outside = (u <= 0)
        c0 = data[outside].sum() / float(outside.sum())
        c1 = data[inside].sum() / float(inside.sum())
        
        # Image attachment.
        dres = np.array(np.gradient(u))
        abs_dres = np.abs(dres).sum(0)
        #aux = abs_dres * (c0 - c1) * (c0 + c1 - 2*data)
        aux = abs_dres * (self.lambda1*(data - c1) ** 2 -
                          self.lambda2*(data - c0) ** 2)
        
        res = np.copy(u)
        res[aux < 0] = 1
        res[aux > 0] = 0
        
        # Smoothing.
        for i in range(self.smoothing):
            res = curvop(res)
        
        self._u = res
500421
def ems(self, value: float) -> 'Size':
        """"""
        raise_not_number(value)
        self.maximum = '{}em'.format(value)
        return self
1046328
def _load_img(handle, target_dtype=np.float32, size=None, **kwargs):
    """"""

    image_pil = PIL.Image.open(handle, **kwargs)

    # resize the image to the requested size, if one was specified
    if size is not None:
        if len(size) > 2:
            size = size[:2]
            log.warning("`_load_img()` received size: {}, trimming to first two dims!".format(size))
        image_pil = image_pil.resize(size, resample=PIL.Image.LANCZOS)

    image_array = np.asarray(image_pil)

    # remove alpha channel if it contains no information
    # if image_array.shape[-1] > 3 and 'A' not in image_pil.mode:
    # image_array = image_array[..., :-1]

    image_dtype = image_array.dtype
    image_max_value = np.iinfo(image_dtype).max  # ...for uint8 that's 255, etc.

    # using np.divide should avoid an extra copy compared to doing division first
    ndimage = np.divide(image_array, image_max_value, dtype=target_dtype)

    rank = len(ndimage.shape)
    if rank == 3:
        return ndimage
    elif rank == 2:
        return np.repeat(np.expand_dims(ndimage, axis=2), 3, axis=2)
    else:
        message = "Loaded image has more dimensions than expected: {}".format(rank)
        raise NotImplementedError(message)
1364580
def render_docstring(self):
        """"""
        res = '{{{self.method}}} {self.uri} {self.title}\n'.format(self=self)
        if self.params:
            for group, params in self.params.items():
                res += '\n' + group + ' params:\n'
                for param in params.values():
                    res += param.render_docstring()
        return res
463841
def get_image(self, img, is_train):
        """"""
        img_arr = mx.image.imread(img)
        img_arr = transform(img_arr, 256, 256, is_train, self.boxes[img])
        return img_arr
1298606
def pil_image(self):
        """"""
        if not self._pil_image:
            if self._format == "SVG":
                raise VectorImageError("can't rasterise vector images")
            self._pil_image = PIL.Image.open(StringIO(self.contents))
        return self._pil_image
1006591
def sed2(img, contour=None, shape=[3, 4]):
    
    """
    :param img:
    :param contour:
    :param shape:
    :return:
    """

    plt.imshow(slices(img, shape), cmap='gray')
    if contour is not None:
        plt.contour(slices(contour, shape))
416687
def decode_example(self, example):
    """"""
    img = tf.image.decode_image(
        example, channels=self._shape[-1], dtype=tf.uint8)
    img.set_shape(self._shape)
    return img