import java.awt.*; import java.awt.image.*; import java.util.*; /** * Code provided for PS-1 * Region growing algorithm: finds and holds regions in an image. * Each region is a list of contiguous points with colors similar to a target color. * Dartmouth CS 10, Winter 2025 * * @author Tim Pierson, Dartmouth CS10, Winter 2025, based on prior terms RegionFinder */ public class RegionFinder { private static final int maxColorDiff = 20; // how similar a pixel color must be to the target color, to belong to a region private static final int minRegion = 50; // how many points in a region to be worth considering private BufferedImage image; // the image in which to find regions private BufferedImage recoloredImage; // the image with identified regions recolored private ArrayList> regions; // a region is a list of points // so the identified regions are in a list of lists of points public RegionFinder() { this.image = null; } public RegionFinder(BufferedImage image) { this.image = image; } public void setImage(BufferedImage image) { this.image = image; } public BufferedImage getImage() { return image; } public BufferedImage getRecoloredImage() { return recoloredImage; } /** * Sets regions to the flood-fill regions in the image, similar enough to the trackColor. */ public void findRegions(Color targetColor) { // TODO: YOUR CODE HERE } /** * Tests whether the two colors are "similar enough" (your definition, subject to the maxColorDiff threshold, which you can vary). */ protected static boolean colorMatch(Color c1, Color c2) { // TODO: YOUR CODE HERE } /** * Returns the largest region detected (if any region has been detected) */ public ArrayList largestRegion() { // TODO: YOUR CODE HERE } /** * Sets recoloredImage to be a copy of image, * but with each region a uniform random color, * so we can see where they are */ public void recolorImage() { // First copy the original recoloredImage = new BufferedImage(image.getColorModel(), image.copyData(null), image.getColorModel().isAlphaPremultiplied(), null); // Now recolor the regions in it // TODO: YOUR CODE HERE } }