bdlb/diabetic_retinopathy_diagnosis/tfds_adapter.py
def _preprocess(
      cls,
      image_fobj,
      target_height: int,
      target_width: int,
      crop: bool = False,
      scale: int = 500,
  ) -> io.BytesIO:
    """Resize an image to have (roughly) the given number of target pixels.

    Args:
      image_fobj: File object containing the original image.
      target_height: `int`, number of pixels in height.
      target_width: `int`, number of pixels in width.
      crops: (optional) `bool`, if True crops the centre of the original
        image t the target size.
      scale: (optional) `int`, the radius of the neighborhood to apply
        Gaussian blur filtering.

    Returns:
      A file object.
    """
    # Decode image using OpenCV2.
    image = cv2.imdecode(np.fromstring(image_fobj.read(), dtype=np.uint8),
                         flags=3)
    try:
      a = cls._get_radius(image, scale)
      b = np.zeros(a.shape)
      cv2.circle(img=b,
                 center=(a.shape[1] // 2, a.shape[0] // 2),
                 radius=int(scale * 0.9),
                 color=(1, 1, 1),
                 thickness=-1,
                 lineType=8,
                 shift=0)
      image = cv2.addWeighted(src1=a,
                              alpha=4,
                              src2=cv2.GaussianBlur(
                                  src=a, ksize=(0, 0), sigmaX=scale // 30),
                              beta=-4,
                              gamma=128) * b + 128 * (1 - b)
    except cv2.error:
      pass
    # Reshape image to target size
    image = cv2.resize(image, (target_height, target_width))
    # Encode the image with quality=72 and store it in a BytesIO object.
    _, buff = cv2.imencode(".jpg", image, [int(cv2.IMWRITE_JPEG_QUALITY), 72])
    return io.BytesIO(buff.tostring())
Resize an image to have (roughly) the given number of target pixels.

    Args:
      image_fobj: File object containing the original image.
      target_height: `int`, number of pixels in height.
      target_width: `int`, number of pixels in width.
      crops: (optional) `bool`, if True crops the centre of the original
        image t the target size.
      scale: (optional) `int`, the radius of the neighborhood to apply
        Gaussian blur filtering.

    Returns:
      A file object.
    
Resize an image to have (roughly) the given number of target pixels.
Resize an image to have ( roughly ) the given number of target pixels .
def _preprocess(
      cls,
      image_fobj,
      target_height: int,
      target_width: int,
      crop: bool = False,
      scale: int = 500,
  ) -> io.BytesIO:
    image = cv2.imdecode(np.fromstring(image_fobj.read(), dtype=np.uint8),
                         flags=3)
    try:
      a = cls._get_radius(image, scale)
      b = np.zeros(a.shape)
      cv2.circle(img=b,
                 center=(a.shape[1] // 2, a.shape[0] // 2),
                 radius=int(scale * 0.9),
                 color=(1, 1, 1),
                 thickness=-1,
                 lineType=8,
                 shift=0)
      image = cv2.addWeighted(src1=a,
                              alpha=4,
                              src2=cv2.GaussianBlur(
                                  src=a, ksize=(0, 0), sigmaX=scale // 30),
                              beta=-4,
                              gamma=128) * b + 128 * (1 - b)
    except cv2.error:
      pass
    image = cv2.resize(image, (target_height, target_width))
    _, buff = cv2.imencode(".jpg", image, [int(cv2.IMWRITE_JPEG_QUALITY), 72])
    return io.BytesIO(buff.tostring())
def _preprocess ( cls , image_fobj , target_height : int , target_width : int , crop : bool = False , scale : int = 500 , ) -> io . BytesIO : image = cv2 . imdecode ( np . fromstring ( image_fobj . read ( ) , dtype = np . uint8 ) , flags = 3 ) try : a = cls . _get_radius ( image , scale ) b = np . zeros ( a . shape ) cv2 . circle ( img = b , center = ( a . shape [ 1 ] // 2 , a . shape [ 0 ] // 2 ) , radius = int ( scale * 0.9 ) , color = ( 1 , 1 , 1 ) , thickness = - 1 , lineType = 8 , shift = 0 ) image = cv2 . addWeighted ( src1 = a , alpha = 4 , src2 = cv2 . GaussianBlur ( src = a , ksize = ( 0 , 0 ) , sigmaX = scale // 30 ) , beta = - 4 , gamma = 128 ) * b + 128 * ( 1 - b ) except cv2 . error : pass image = cv2 . resize ( image , ( target_height , target_width ) ) _ , buff = cv2 . imencode ( ".jpg" , image , [ int ( cv2 . IMWRITE_JPEG_QUALITY ) , 72 ] ) return io . BytesIO ( buff . tostring ( ) )
Resize an image to have (roughly) the given number of target pixels.
Resize an image to have ( roughly ) the given number of target pixels .
"""Resize an image to have (roughly) the given number of target pixels.

    Args:
      image_fobj: File object containing the original image.
      target_height: `int`, number of pixels in height.
      target_width: `int`, number of pixels in width.
      crops: (optional) `bool`, if True crops the centre of the original
        image t the target size.
      scale: (optional) `int`, the radius of the neighborhood to apply
        Gaussian blur filtering.

    Returns:
      A file object.
    """ # Decode image using OpenCV2. # Reshape image to target size # Encode the image with quality=72 and store it in a BytesIO object.
A file object.
A file object .
cls
image_fobj
File object containing the original image.
File object containing the original image .
target_height
int
`int`, number of pixels in height.
` int ` number of pixels in height .
target_width
int
`int`, number of pixels in width.
` int ` number of pixels in width .
crop
bool
scale
int
(optional) `int`, the radius of the neighborhood to apply
Gaussian blur filtering.
( optional ) ` int ` the radius of the neighborhood to apply Gaussian blur filtering .
crops
(optional) `bool`, if True crops the centre of the original
image t the target size.
( optional ) ` bool ` if True crops the centre of the original image t the target size .