-
-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-image): 新增形态学,图片转01,图片处理功能
- Loading branch information
Showing
14 changed files
with
269 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
group = "me.leon.toolsfx" | ||
version = "1.1.0" | ||
version = "1.2.0" | ||
|
||
plugins { | ||
`java-library` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mage/src/test/kotlin/me/leon/img/Color.kt → ...otlin/me/leon/toolsfx/plugin/ext/Color.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package me.leon.img | ||
package me.leon.toolsfx.plugin.ext | ||
|
||
import java.awt.Color | ||
|
||
|
11 changes: 11 additions & 0 deletions
11
plugin-image/src/main/kotlin/me/leon/toolsfx/plugin/ext/ColorMode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package me.leon.toolsfx.plugin.ext | ||
|
||
/** | ||
* @author Leon | ||
* @since 2022-12-23 15:59 | ||
* @email [email protected] | ||
*/ | ||
enum class ColorMode { | ||
WHITE1, | ||
BLACK1 | ||
} |
25 changes: 25 additions & 0 deletions
25
plugin-image/src/main/kotlin/me/leon/toolsfx/plugin/ext/ImageConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package me.leon.toolsfx.plugin.ext | ||
|
||
/** | ||
* @author Leon | ||
* @since 2022-12-23 15:27 | ||
* @email [email protected] | ||
*/ | ||
const val OPTIONS = "options" | ||
const val HINT = "hint" | ||
val IMAGE_CONFIG = | ||
mapOf( | ||
ImageServiceType.ZERO_ONE_QR_IMAGE to | ||
mapOf(OPTIONS to arrayOf(ColorMode.BLACK1.toString(), ColorMode.WHITE1.toString())), | ||
ImageServiceType.ZERO_ONE_IMAGE to | ||
mapOf(OPTIONS to arrayOf(ColorMode.BLACK1.toString(), ColorMode.WHITE1.toString())), | ||
ImageServiceType.IMAGE_TO_01 to | ||
mapOf(OPTIONS to arrayOf(ColorMode.WHITE1.toString(), ColorMode.BLACK1.toString())), | ||
ImageServiceType.IMAGE_PROCESS to | ||
mapOf(OPTIONS to ImageOperation.values().map { it.toString() }.toTypedArray()), | ||
ImageServiceType.MORPHOLOGY to | ||
mapOf( | ||
HINT to arrayOf("kernel size default is 3"), | ||
OPTIONS to ImageMorphology.values().map { it.toString() }.toTypedArray() | ||
) | ||
) |
44 changes: 44 additions & 0 deletions
44
plugin-image/src/main/kotlin/me/leon/toolsfx/plugin/ext/ImageMorphology.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package me.leon.toolsfx.plugin.ext | ||
|
||
import me.leon.P1 | ||
import me.leon.ext.toFile | ||
|
||
/** | ||
* 图像形态学,需要变成二值图 需要指定kernel大小 | ||
* | ||
* @author Leon | ||
* @since 2022-12-23 16:48 | ||
* @email [email protected] | ||
*/ | ||
enum class ImageMorphology : SimpleService { | ||
ERODE { | ||
override fun process(file: String, params: Map<String, String>) = | ||
file.toFile().toBufferImage().binary().erode(params.parseParams()) | ||
}, | ||
DILATE { | ||
override fun process(file: String, params: Map<String, String>) = | ||
file.toFile().toBufferImage().binary().dilate(params.parseParams()) | ||
}, | ||
OPEN_OP { | ||
override fun process(file: String, params: Map<String, String>) = | ||
file.toFile().toBufferImage().binary().openOp(params.parseParams()) | ||
}, | ||
CLOSE_OP { | ||
override fun process(file: String, params: Map<String, String>) = | ||
file.toFile().toBufferImage().binary().closeOp(params.parseParams()) | ||
}, | ||
GRADIENT { | ||
override fun process(file: String, params: Map<String, String>) = | ||
file.toFile().toBufferImage().binary().gradient(params.parseParams()) | ||
}, | ||
BLACK_HAT { | ||
override fun process(file: String, params: Map<String, String>) = | ||
file.toFile().toBufferImage().binary().blackHat(params.parseParams()) | ||
}, | ||
TOP_HAT { | ||
override fun process(file: String, params: Map<String, String>) = | ||
file.toFile().toBufferImage().binary().topHat(params.parseParams()) | ||
}; | ||
|
||
fun Map<String, String>.parseParams() = requireNotNull(this[P1]).ifEmpty { "3" }.toInt() | ||
} |
39 changes: 39 additions & 0 deletions
39
plugin-image/src/main/kotlin/me/leon/toolsfx/plugin/ext/ImageOperation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package me.leon.toolsfx.plugin.ext | ||
|
||
import me.leon.ext.toFile | ||
|
||
/** | ||
* @author Leon | ||
* @since 2022-12-23 16:42 | ||
* @email [email protected] | ||
*/ | ||
enum class ImageOperation : SimpleService { | ||
GRAY { | ||
override fun process(file: String, params: Map<String, String>) = | ||
file.toFile().toBufferImage().gray() | ||
}, | ||
BINARY { | ||
override fun process(file: String, params: Map<String, String>) = | ||
with(file.toFile().toBufferImage()) { binary(ostu()) } | ||
}, | ||
INVERSE { | ||
override fun process(file: String, params: Map<String, String>) = | ||
file.toFile().toBufferImage().inverse() | ||
}, | ||
MIRROR_HEIGHT { | ||
override fun process(file: String, params: Map<String, String>) = | ||
file.toFile().toBufferImage().mirrorHeight() | ||
}, | ||
MIRROR_WIDTH { | ||
override fun process(file: String, params: Map<String, String>) = | ||
file.toFile().toBufferImage().mirrorWidth() | ||
}, | ||
MOSAIC { | ||
override fun process(file: String, params: Map<String, String>) = | ||
file.toFile().toBufferImage().mosaic() | ||
}, | ||
OIL_PAINT { | ||
override fun process(file: String, params: Map<String, String>) = | ||
file.toFile().toBufferImage().oilPaint() | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
plugin-image/src/main/kotlin/me/leon/toolsfx/plugin/ext/ImageService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package me.leon.toolsfx.plugin.ext | ||
|
||
interface ImageService { | ||
|
||
fun process(raw: String, isFile: Boolean, params: Map<String, String>): Any | ||
fun paramsHints(): Array<out String> | ||
fun options(): Array<out String> | ||
} |
Oops, something went wrong.