Lab 11 FAQ

The spec’s interactive parts

The energy quiz says I’m wrong but I’m sure I’m right

Square each of the six differences (three colors × two directions) and add all six squares. The answer is a plain integer with no decimal point. Open “Show the work” under the quiz to compare line by line.

I can’t get the 10-by-10 seam right

The page only lets you pick top to bottom, one of the three pixels below your last pick each time (they’re outlined with a dashed border), and shows the running total under the picture. If the checker says a cheaper seam exists, don’t just patch the expensive pixel it points at; click a different pixel in the top row and start over from there. The cheapest top pixel is a trap.

computeM and findSeamFromM

Where do the energies come from?

They’re already computed for you: energy[x][y] (a double[][] field) or energy(x, y) (the method) give the energy of pixel (x, y). You don’t need to touch Colors at all.

Which test should I run first?

testComputeMOnSpecGrid checks your computeM against the full $M$ table for the 10-by-10 grid in the spec. testFindSeamFromMOnSpecGrid hands your findSeamFromM the correct $M$ for that grid, so it tells you about that method alone, even if computeM is still wrong. Get those two green before looking at the image tests.

testVerticalSeam6x5 expects different columns but my total energy is the same

For that image the minimum seam is unique, so a different answer with the same total energy means some entries of your $M$ table are wrong. For the other images, testAllReferenceImages only compares total energy, since ties can be broken either way.

My seam jumps by more than one column between rows

When walking back up the table, only look at the three pixels directly above-left, above, and above-right of the current one (and only the ones that exist: column −1 and column width() don’t). Picking the global minimum of the row above produces an invalid seam, and removeVerticalSeam will throw an IllegalArgumentException telling you which two rows are too far apart.

testHorizontalSeam6x5 fails but my vertical seams are right

findHorizontalSeam is provided; it transposes the energy table and calls your computeM and findSeamFromM on it. So those two must get their sizes from the table they are handed (e.length by e[0].length), not from width(), height(), or the energy field, which describe the untransposed picture.

Everything passes but the visualizer is slow

Use plain 2D arrays, not HashMaps, and avoid Math.pow. At reduced scale (largest side 500) the reference solution finds a seam in a few milliseconds.

The visualizer

Nothing opens in my browser

Look at the console for the line Visualizer is being served at http://localhost:4567/ and open that address yourself.

“Address already in use”

Another program is already listening on port 4567, most likely a visualizer from Lab 9 or 10 that is still running. Stop it (in IntelliJ, the red square next to the run tab) and run SeamCarverVisualizer again.

The page says findVerticalSeam returned null or threw an exception

It returns null whenever your computeM or findSeamFromM still does.

That’s the page telling you what to work on. Implement or fix it, then stop the program and re-run SeamCarverVisualizer. Refreshing the browser alone won’t help, since the old code is still running in the server.

I changed my code but the visualizer behaves the same

Same answer: stop the running program and re-run it. The browser page talks to whatever SeamCarver the Java program compiled when it started.

The red line looks nothing like a seam

The visualizer draws exactly the array your findSeamFromM returned, so this means your seam is wrong, not the drawing. Run PrintSeams on a small image like images/6x5.png and compare to images/6x5.printseams.txt.

Full scale or reduced scale?

Reduced scale, unless you’re patient. Every seam costs time proportional to the number of pixels, plus the time to send the new picture to the browser, so a 4000 × 3000 phone photo takes a few seconds per seam at full scale and needs thousands of seams to shrink noticeably. At reduced scale (largest side 500 pixels) a seam takes a few milliseconds. The 500 is REDUCED_MAX_DIMENSION in SeamCarverVisualizerInternals if you want a different size.