U-2-Net icon indicating copy to clipboard operation
U-2-Net copied to clipboard

320*320 size issue

Open brittle123 opened this issue 4 years ago • 3 comments
trafficstars

I used your model in my android app and it's working perfectly fine for me but there is only one issue. When i give an image to the model it returns me the resized background removed image mask of 320*320. How can i get the original size?

brittle123 avatar Aug 25 '21 06:08 brittle123

you need to load the original image and get its shape, then use bilinear upsampling to resize the predicted probability maps (such as resize function in skimage: https://scikit-image.org/docs/stable/auto_examples/transform/plot_rescale.html). You can then get the background removed image by concate the original image and the resized probability map.

On Wed, Aug 25, 2021 at 10:40 AM brittle123 @.***> wrote:

I used your model and it's working perfectly fine for me but there is only one issue. When i give an image to the model it returns me the resized background removed image of 320*320. How can i get the original size?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/xuebinqin/U-2-Net/issues/248, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSGORLT2TAAMZHZMGUP4V3T6SF4PANCNFSM5CYLJQCQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

-- Xuebin Qin PhD Department of Computing Science University of Alberta, Edmonton, AB, Canada Homepage:https://webdocs.cs.ualberta.ca/~xuebin/

xuebinqin avatar Aug 25 '21 06:08 xuebinqin

I didn't get your exact point. Can you please guide me how to do it in android. Here is my code:

val scaledBitmap =
              scaleBitmapAndKeepRatio(
                      data,
                      imageSize, imageSize
              )

fun scaleBitmapAndKeepRatio(
      targetBmp: Bitmap,
      reqHeightInPixels: Int,
      reqWidthInPixels: Int
    ): Bitmap {
      if (targetBmp.height == reqHeightInPixels && targetBmp.width == reqWidthInPixels) {
        return targetBmp
      }
      val matrix = Matrix()
      matrix.setRectToRect(
        RectF(
          0f, 0f,
          targetBmp.width.toFloat(),
          targetBmp.width.toFloat()
        ),
        RectF(
          0f, 0f,
          reqWidthInPixels.toFloat(),
          reqHeightInPixels.toFloat()
        ),
        Matrix.ScaleToFit.FILL
      )
      return Bitmap.createBitmap(
        targetBmp, 0, 0,
        targetBmp.width,
        targetBmp.width, matrix, true
      )
    }

Here in this function i have passed data (original image bitmap) and imagesize (width &Height) and imagesize is 320. If I pass width and height less or more then 320 then this model is not giving me any masked bitmap.

brittle123 avatar Aug 25 '21 09:08 brittle123

@brittle123 can you please share the repo. I need that too.

ahmadbajwa8282 avatar Sep 01 '22 09:09 ahmadbajwa8282