private static void TestMatch(BufferedImage image1, BufferedImage image2, int x1, int y1, int x2, int y2, boolean source)
{
if(source)
{
minX = image1.getWidth()-1;
minY = image1.getHeight()-1;
maxX = 0;
maxY = 0;
tempVisitedPixels2 = new boolean [image2.getHeight()][image2.getWidth()];
semiRecordedPoints = new ArrayList<String>();
differentColors = new ArrayList<Color>();
notQuiteRecorded = new boolean[image1.getHeight()][image1.getWidth()];
}
if( ( ((x1 >= 0 && y1 >= 0) && (x2 >= 0 && y2 >= 0)) && (x1 <= image1.getWidth()-1 && x2 <= image2.getWidth()-1)) && ((y1 <= image1.getHeight()-1) && (y2 <= image2.getHeight()-1)) )
{
if((tempVisitedPixels2[y2][x2] == false && blankPixels2[y2][x2] == false) && (linkedPixels[y1][x1] == false && tempBlankPixels1[y1][x1] == false))
{
if(new Color(image1.getRGB(x1, y1)).equals(new Color(image2.getRGB(x2, y2))))
{
if(differentColors.indexOf(new Color(image1.getRGB(x1, y1))) == -1)
differentColors.add(new Color(image1.getRGB(x1, y1)));
if(x1 < minX)
minX = x1;
if(y1 < minY)
minY = y1;
if(x1 > maxX)
maxX = x1;
if(y1 > maxY)
maxY = y1;
tempVisitedPixels2[y2][x2] = true;
semiRecordedPoints.add("(" + String.valueOf(x1) + "," + String.valueOf(y1) + ") = (" + String.valueOf(x2) + "," + String.valueOf(y2) + ")");
notQuiteRecorded[y1][x1] = true;
displayPanel.repaint();
TestMatch(image1, image2, x1 + 1, y1, x2 + 1, y2, false);
TestMatch(image1, image2, x1 + 1, y1 + 1, x2 + 1, y2 + 1, false);
TestMatch(image1, image2, x1, y1 + 1, x2, y2 + 1, false);
TestMatch(image1, image2, x1 - 1, y1 + 1, x2 - 1, y2 + 1, false);
TestMatch(image1, image2, x1 - 1, y1, x2 - 1, y2, false);
TestMatch(image1, image2, x1 - 1, y1 - 1, x2 - 1, y2 - 1, false);
TestMatch(image1, image2, x1, y1 - 1, x2, y2 - 1, false);
TestMatch(image1, image2, x1 + 1, y1 - 1, x2 + 1, y2 - 1, false);
}
}
tempVisitedPixels2[y2][x2] = true;
if(source)
{
boolean sufficient;
if(differentColors.size() < 3)
sufficient = false;
else if(differentColors.size() == 3)
sufficient = (semiRecordedPoints.size() >= 45);
else if(differentColors.size() == 4)
sufficient = (semiRecordedPoints.size() >= 22);
else if(differentColors.size() == 5)
sufficient = (semiRecordedPoints.size() >= 15);
else //(differentColors.size() >= 6)
sufficient = (semiRecordedPoints.size()*differentColors.size() >= 40);
if(sufficient)
{
checkBlobs = true;
for(int i = 0; i < semiRecordedPoints.size(); i++)
{
linkedPixels[Integer.parseInt(semiRecordedPoints.get(i).substring(semiRecordedPoints.get(i).indexOf(",")+1,
semiRecordedPoints.get(i).indexOf(")")))][Integer.parseInt(semiRecordedPoints.get(i).substring(1, semiRecordedPoints.get(i).indexOf(",")))] = true;
linkedPixel[Integer.parseInt(semiRecordedPoints.get(i).substring(semiRecordedPoints.get(i).indexOf(",")+1,
semiRecordedPoints.get(i).indexOf(")")))][Integer.parseInt(semiRecordedPoints.get(i).substring(1, semiRecordedPoints.get(i).indexOf(",")))]
= semiRecordedPoints.get(i).substring(semiRecordedPoints.get(i).indexOf("=")+2);
linkedPixels2[Integer.parseInt(semiRecordedPoints.get(i).substring(nthOccurrence(semiRecordedPoints.get(i), (char)(44), 1)+1,
semiRecordedPoints.get(i).length()-1))] [Integer.parseInt(semiRecordedPoints.get(i).substring(nthOccurrence(semiRecordedPoints.get(i),
(char)(40), 1)+1, nthOccurrence(semiRecordedPoints.get(i), (char)(44), 1)))] = true;
numberOfLinkedPixels++;
}
}
}
}
}