demoFelzenszwalbSegmentation.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. % demoFelzenszwalbSegmentation
  2. %
  3. % author: Alexander Freytag
  4. % date: 28-03-2014 (dd-mm-yyyy)
  5. %
  6. % brief: small demo showing how to use the felzenszwalb segmentation code
  7. % via Matlab and how to adjust parameter specifications.
  8. %% ( 1 ) GET INPUT
  9. %read image ...
  10. img = imread( 'data/test.png');
  11. % show input image in figure
  12. figOrig = figure;
  13. set ( figOrig, 'name', 'Input image');
  14. imshow ( img );
  15. %% ( 2 ) PERFORM SEGMENTATION WITH DEFAULT SETTINGS
  16. % call felzenszwalb segmentation using our mex-interface
  17. segResult = segmentFelzenszwalb( img );
  18. % show segmentation result in separate figure
  19. figSegResult = figure;
  20. set ( figSegResult, 'name', 'Segmentation result');
  21. imshow ( segResult );
  22. % make region colors visually distinguishable
  23. colormap ( 'lines' );
  24. %% ( 3 ) PERFORM SEGMENTATION WITH SPECIFIED SETTINGS
  25. d_sigma = 0.75; % default: 0.5
  26. i_k = 700; % default: 500
  27. i_minSize = 50; % default: 50
  28. b_computeColorOutput = true; % default: false
  29. s_destination = ''; % default: ''
  30. b_verbose = false; % default: false
  31. srManSpec = segmentFelzenszwalb( img, d_sigma, i_k, i_minSize, ...
  32. b_computeColorOutput, ...
  33. s_destination, ...
  34. b_verbose...
  35. );
  36. % show segmentation result in separate figure
  37. figSRManSpec = figure;
  38. set ( figSRManSpec, 'name', 'Segmentation result, man. specified');
  39. imshow ( srManSpec );
  40. % actually, another linespec is not needed, since the output is already a
  41. % nice RGB image. However, for easier visual comparison, we again apply the
  42. % matlab color mapping here.
  43. colormap ( 'lines' );
  44. % wait for user input
  45. pause
  46. % close images
  47. close ( figOrig );
  48. close ( figSegResult );
  49. close ( figSRManSpec );