readImage.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. function im = readImage( s_imageName, settings )
  2. % function im = readImage( s_imageName, settings )
  3. %
  4. % author: Alexander Freytag
  5. % date: 31-03-2014 ( dd-mm-yyyy )
  6. %
  7. % BRIEF: read an image from filename, possible repeate a gray value image
  8. % to result in 3 dimensions (pseudo-RGB)
  9. %
  10. % INPUT:
  11. % s_imageName -- char array ( filename to image )
  12. % settings -- struct (optional), with useable fields
  13. % 'b_resizeImageToStandardSize',
  14. % 'i_standardImageSize'
  15. %
  16. % OUTPUT:
  17. % im -- h x w x 3 uint8 image
  18. %
  19. if( nargin < 2 )
  20. settings = [];
  21. end
  22. %% (1) READ IMAGE FROM FILENAME
  23. im = imread( s_imageName );
  24. %% (2) RESIZING TO STANDARD SIZE IF DESIRED
  25. if ( getFieldWithDefault (settings, 'b_resizeImageToStandardSize', false ) )
  26. i_standardImageSize = getFieldWithDefault ( settings, 'i_standardImageSize', [128,128]);
  27. if ( ndims(i_standardImageSize) == 1)
  28. i_standardImageSize = repmat(i_standardImageSize, [1,2]);
  29. end
  30. im = imresize(im, i_standardImageSize);
  31. end
  32. %% (3) MAKE IMAGE ALWAYS TO BE COLOR, OR PSEUDO COLOR
  33. if( ndims( im ) == 2 )
  34. im = repmat ( im, [1,1,3] );
  35. end
  36. end