mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-26 08:54:42 +01:00
Refactor: simplify code
This commit is contained in:
parent
4d1905863b
commit
12542856a0
3 changed files with 10 additions and 13 deletions
|
@ -2,10 +2,11 @@ package com.nkming.nc_photos.plugin.image_processor
|
|||
|
||||
import android.content.Context
|
||||
import android.content.res.AssetManager
|
||||
import android.graphics.*
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import com.nkming.nc_photos.plugin.BitmapResizeMethod
|
||||
import com.nkming.nc_photos.plugin.BitmapUtil
|
||||
import com.nkming.nc_photos.plugin.use
|
||||
|
||||
/**
|
||||
* DeepLab is a state-of-art deep learning model for semantic image
|
||||
|
@ -23,12 +24,10 @@ class DeepLab3Portrait(
|
|||
val rgb8Image = BitmapUtil.loadImage(
|
||||
context, imageUri, maxWidth, maxHeight, BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true, shouldUpscale = false
|
||||
).let {
|
||||
).use {
|
||||
width = it.width
|
||||
height = it.height
|
||||
val rgb8 = TfLiteHelper.bitmapToRgb8Array(it)
|
||||
it.recycle()
|
||||
rgb8
|
||||
TfLiteHelper.bitmapToRgb8Array(it)
|
||||
}
|
||||
val am = context.assets
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.graphics.Bitmap
|
|||
import android.net.Uri
|
||||
import com.nkming.nc_photos.plugin.BitmapResizeMethod
|
||||
import com.nkming.nc_photos.plugin.BitmapUtil
|
||||
import com.nkming.nc_photos.plugin.use
|
||||
|
||||
class Esrgan(context: Context, maxWidth: Int, maxHeight: Int) {
|
||||
fun infer(imageUri: Uri): Bitmap {
|
||||
|
@ -15,12 +16,10 @@ class Esrgan(context: Context, maxWidth: Int, maxHeight: Int) {
|
|||
context, imageUri, maxWidth / 4, maxHeight / 4,
|
||||
BitmapResizeMethod.FIT, isAllowSwapSide = true,
|
||||
shouldUpscale = false
|
||||
).let {
|
||||
).use {
|
||||
width = it.width
|
||||
height = it.height
|
||||
val rgb8 = TfLiteHelper.bitmapToRgb8Array(it)
|
||||
it.recycle()
|
||||
rgb8
|
||||
TfLiteHelper.bitmapToRgb8Array(it)
|
||||
}
|
||||
val am = context.assets
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.graphics.Bitmap
|
|||
import android.net.Uri
|
||||
import com.nkming.nc_photos.plugin.BitmapResizeMethod
|
||||
import com.nkming.nc_photos.plugin.BitmapUtil
|
||||
import com.nkming.nc_photos.plugin.use
|
||||
|
||||
class ZeroDce(context: Context, maxWidth: Int, maxHeight: Int, iteration: Int) {
|
||||
fun infer(imageUri: Uri): Bitmap {
|
||||
|
@ -14,12 +15,10 @@ class ZeroDce(context: Context, maxWidth: Int, maxHeight: Int, iteration: Int) {
|
|||
val rgb8Image = BitmapUtil.loadImage(
|
||||
context, imageUri, maxWidth, maxHeight, BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true, shouldUpscale = false
|
||||
).let {
|
||||
).use {
|
||||
width = it.width
|
||||
height = it.height
|
||||
val rgb8 = TfLiteHelper.bitmapToRgb8Array(it)
|
||||
it.recycle()
|
||||
rgb8
|
||||
TfLiteHelper.bitmapToRgb8Array(it)
|
||||
}
|
||||
val am = context.assets
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue