I am reading tiff file and extracting bounding box images now based on confidence value of each character I want to separate some images and consolidate to one image file for training dataset.
Asked
Active
Viewed 207 times
-2
-
Possible duplicate of [How to combine multiple PNGs into one big PNG file?](https://stackoverflow.com/questions/3922276/how-to-combine-multiple-pngs-into-one-big-png-file) – Dmitrii Z. Oct 07 '18 at 13:59
-
Hi @DmitriiZ. I was not looking for the combination of multiple PNG files into one. I have given the answer for what I was looking for as I was able to crack it. – Ankit Oct 28 '18 at 08:59
1 Answers
0
BufferedImage[] input = new BufferedImage[count-1];
//Load each input image.
for(int index=0; index<input.length; index++) {
try {
File f = new File("folder_path\\"+img_"+
(index+1)+".tiff");
input[index] = ImageIO.read(f);
}
catch(Exception e) {
e.printStackTrace();
}
}
int offset = 5, width=0, height=input[0].getHeight();
for(int index=0; index<input.length; index++) {
width+=input[index].getWidth();
if(height<input[index].getHeight())
{
height=input[index].getHeight();
}
}
width+=count*offset;
height+=offset;
//Create Output image
BufferedImage output = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = output.createGraphics();
Color oldColor = g2.getColor();
//fill background
g2.setPaint(Color.WHITE);
g2.fillRect(0, 0, width, height);
//draw image
g2.setColor(oldColor);
int xcordinate=0;
for(int index=0; index<input.length; index++) {
g2.drawImage(input[index], null, xcordinate, 0);
xcordinate+=input[index].getWidth()+offset;
}
g2.dispose();
File merged = new File("folder_path\\"+merged_2_new.tiff");
try {
ImageIO.write(output, "tiff", merged);
}
catch(Exception e) {
e.printStackTrace();
}

Ankit
- 1
- 2
-
Here, First I extracted all the tiff files which I want to merge in a folder then gave it as input to BufferedImage[]. – Ankit Oct 10 '18 at 10:06