AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
aud.example.dp.SeamCarvingDemo Class Reference

Simple implementation of seam carving. More...

+ Collaboration diagram for aud.example.dp.SeamCarvingDemo:

Static Public Member Functions

static void main (String[] args)
 

Static Protected Member Functions

static void usage ()
 print help message and exit More...
 

Detailed Description

Simple implementation of seam carving.

Seam carving is a method for resizing images such that (important) content is not scaled or distorted. Instead, unimportant content is removed, by removing seams of connected pixels in vertical or horizontal direction. The computation of "optimal" seams, i.e., the decision which pixels are to be removed, is based on Dynamic Programming.

This demo implements part of the original article

Shai Avidan and Ariel Shamir. Seam carving for content-aware image resizing, SIGGRAPH 2007

with the following main restrictions:

  • We remove only vertical seams, i.e., reduce the width of the image.
  • We remove seams one by one. There are more efficient implementations. (Hint: Use the index_map_.)
  • The importance map is generated from gradient magnitude using a Sobel operator. (This is not part of the core algorithm.)

Definition at line 36 of file SeamCarvingDemo.java.

Member Function Documentation

◆ main()

static void aud.example.dp.SeamCarvingDemo.main ( String[]  args)
static

Definition at line 343 of file SeamCarvingDemo.java.

343 {
344 if (args.length < 3)
345 usage();
346
347 try {
348 BufferedImage image = ImageIO.read(new File(args[0]));
349 int n = Integer.parseInt(args[1]);
350
351 int nmax = image.getWidth() - 1;
352 n = Math.max(0, Math.min(nmax, n));
353 SeamCarvingDemo seam_carving = new SeamCarvingDemo(image);
354 seam_carving.apply(n);
355 seam_carving.write_result(args[2]);
356
357 if (args.length > 3)
358 seam_carving.dump_seams(args[3]);
359
360 if (args.length > 4)
361 seam_carving.dump_importance(args[4]);
362
363 } catch(IOException e) {
364 System.err.println(e);
365 System.exit(-1);
366 }
367 }
static void usage()
print help message and exit

References aud.example.dp.SeamCarvingDemo.usage().

+ Here is the call graph for this function:

◆ usage()

static void aud.example.dp.SeamCarvingDemo.usage ( )
staticprotected

print help message and exit

Definition at line 330 of file SeamCarvingDemo.java.

330 {
331 System.err.println
332 ("usage: java aud.example.dp.SeamCarvingDemo IMAGE N OUTPUT " +
333 "[DUMP-SEAMS] [DUMP-IMPORTANCE]]\n\n" +
334 "Read IMAGE and shrink horizontally by removing N vertical seams.\n" +
335 "If the filename DUMP-SEAMS is specified, write an image that " +
336 "shows the generated seams.\n" +
337 "If the filename DUMP-IMPORTANCE is specified, the generated " +
338 "importance map is saved to this file.\n"
339 );
340 System.exit(-1);
341 }

Referenced by aud.example.dp.SeamCarvingDemo.main().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: