Click here to Skip to main content
15,443,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am working on image processing project in that i have two images
image1-
image2-
in that images road is present in white pixels in both images means (r=255,g=255,b=255)
i want to connect both images image1 is above and image2 is bellow .in that i want to compare last row of image1 and first row of image2 .if i find white pixel then i want to getting connected white pixel in both images due to complete image is form . in that complete only road is present other pixel is black (means only white connected pixel is present in that hole image and other part is black pixel)means unconnected white pixel are deleted
image look like-
i am retrieving pixel of both image
code image1
Java
package testing1;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import javax.imageio.ImageIO;

public class test2 {

	static ArrayList l2 = new ArrayList();

	public test2() throws IOException {
		// new test1();

		BufferedImage img = ImageIO.read(new File("img0.png"));

		final int height = img.getHeight();
		final int width = img.getWidth();
		// int newwidth=width-1;
		// int newheight=height-1;
		int countrow = 0;
		int countcol = 0;
		int newrow = width - 1;

		for (int i = 0; i < width; i++) {
			for (int j = 0; j < height; j++) {
				if (countrow == newrow) {
					Color c = new Color(img.getRGB(i, j));
					int a = c.getRed();
					l2.add(a);

				}

				countcol++;

			}
			countrow++;

		}
		System.out.println("test2col" + countcol);
		System.out.println("test2row" + countrow);
	}

}


 code image2
package testing1;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import javax.imageio.ImageIO;

public class test1 {
	static ArrayList l1 = new ArrayList();
	static int height;
	static int width;

	public test1() throws IOException {

		BufferedImage img = ImageIO.read(new File("img2.png"));

		height = img.getHeight();
		width = img.getWidth();
		int countrow = 0;
		int countcol = 0;

		for (int i = 0; i < width; i++) {
			for (int j = 0; j < height; j++) {
				Color c = new Color(img.getRGB(i, j));
				int a = c.getRed();
				l1.add(a);
				// System.out.println(l1);

				countcol++;

			}
			countrow++;
			// break;
			if (countrow == 1) {

				continue;

			} else {

			}
			break;

		}
	}

}
Posted
Comments
_Maxxx_ 3-Dec-13 22:15pm     CRLF
Difficult to follow what you are asking exactly. From what I can tell of your code, you have two arrays containing all the values for the red pixels from both images? Anyway, Assuming both the images are the same width, then you just need to look at the bottom row of the top image and the top row of the bottom image. from left to right, (i.e. from i=0 to i=width) compare the pixel values from each. I don't really understand what you want to do with the images once you determine if the pixel values are equal, though. Maybe try re-wording your question as a series of short steps as the English may be easier to understand.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900