Mango
Mango

Reputation: 79

How to combine multiple split images with overlapping back into an original image by using java?

I have 2 images as following:

image part 1

image part 2

I would like to combine them automatically, hopefully it can be done in Java

combined images

How to detect the pixel location and correct edges to combine both images, due to both images have overlapping and without knowing which is the correct edges to combine? Any algorithm can be provided?

Upvotes: 1

Views: 750

Answers (1)

Codey McCodeface
Codey McCodeface

Reputation: 3028

ImageJ is a very good java image processing library. It may have plugins out there to do this already so perhaps worth a check.

I would start by trying to find a location in both images that is the same. Do a line profile across both images vertically and see if the pixel values and y values are the same. If the images are exactly the same in only one location then it should be easy. If there are multiple locations where the pixels are the same or the pixels in the y direction are never the same then I think your problem may not have a uniquie solution.

Here is some code to get you started

public class CombineImages implements PlugIn
{


@Override
public void run(String arg0) {
    // TODO Auto-generated method stub

}

public ImagePlus combineImages(ImageProcessor ip1, ImageProcessor ip2){

    //Get a line of Y pixel values for the first image for each x position and add them to a list
    ArrayList<Roi> roiList1 = new ArrayList<Roi>();
    for(int i=0; i<ip1.getWidth()-1; i++){
    Roi roi = new Roi(i,i+1,1, ip1.getHeight());
    roiList1.add(roi);
    }

    //Get a line of Y pixel values for the second image for each x position and add them to a list
    ArrayList<Roi> roiList2 = new ArrayList<Roi>();
    for(int i=0; i<ip2.getWidth()-1; i++){
    Roi roi = new Roi(i,i+1,1, ip2.getHeight());
    roiList2.add(roi);
    }

    //Check if these are the same and return the X values for both images that these correspond to

    //You can then crop and combine the pixel values

    return null;
}

}

Upvotes: 2

Related Questions