[英]How to change the image background to white?
I have set of images. 我有一组图像。 Images have a simple background.
图像背景简单。 I want to change that background to white using Marvin Framework and Java.
我想使用Marvin Framework和Java将该背景更改为白色。
As I am new to Marvin, it is making me trouble to change the background. 因为我是Marvin的新手,所以改变背景让我很麻烦。 I also tried opencv for java but its giving unsatisfied link error.
我也尝试过opencv for java但它给出了不满意的链接错误。
Image Example: 图片示例:
To get a perfect result you'll need to find a way to remove shadows. 要获得完美的结果,您需要找到一种去除阴影的方法。 But I think it is a good start point for you.
但我认为这对你来说是一个很好的起点。
Algorithm: 算法:
output: 输出:
source code: 源代码:
import static marvin.MarvinPluginCollection.*;
public class RemoveBackground {
public RemoveBackground(){
MarvinImage image = MarvinImageIO.loadImage("./res/shoes.jpg");
MarvinImage bin = MarvinColorModelConverter.rgbToBinary(image, 116);
morphologicalDilation(bin.clone(), bin, MarvinMath.getTrueMatrix(5, 5));
MarvinImage mask = MarvinColorModelConverter.binaryToRgb(bin);
boundaryFill(mask.clone(), mask, 5, 5, new Color(255,0,255));
for(int y=0; y<mask.getHeight(); y++){
for(int x=0; x<mask.getWidth(); x++){
if(mask.getIntColor(x, y) == 0xFFFF00FF){
image.setIntColor(x, y, 255,255,255);
}
}
}
MarvinImageIO.saveImage(image, "./res/shoes_out.jpg");
}
public static void main(String[] args) {
new RemoveBackground();
System.exit(0);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.