EDIT
I found the solution. As the question is closed, I cannot post it as an answer.
Original question
I am new to image processing in java and I am trying to convert an image to stencil (I think stencil is name given for it!).
The input image is this:-
After processing the image would be like this:-
I searched google. But could find a solution. (maybe because I don't know what is the actual name of this process.)
Is this possible with java?
CodePudding user response:
Yes I found the solution. if we Binarize an image it will work.
Input image:-
Output Image:-
Code:-
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Main {
public static void main(String[] args) throws IOException {
BufferedImage bi = ImageIO.read(new File("D:\\IMG_20211029_124954.jpg"));
ImageIO.write(binarizeImage(bi), "png", new File("D:\\1.png"));
}
public static BufferedImage binarizeImage(BufferedImage img_param)
{
BufferedImage image = new BufferedImage(
img_param.getWidth(),
img_param.getHeight(),
BufferedImage.TYPE_BYTE_BINARY
);
Graphics g = image.getGraphics();
g.drawImage(img_param, 0, 0, null);
g.dispose();
return image;
}
}