Mercurial > hg > octave-image
changeset 871:714073ad045f
im2bw.m: display image instead of printint to stdout, when nargout is zero.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Tue, 18 Feb 2014 23:10:42 +0000 |
parents | 5e598ccaf0c7 |
children | f1cf02800a87 |
files | NEWS inst/im2bw.m |
diffstat | 2 files changed, 40 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS +++ b/NEWS @@ -1,6 +1,12 @@ Summary of important user-visible changes for image 2.4.0 (yyyy/mm/dd): ------------------------------------------------------------------------- + ** The following functions will display the output image as a figure + instead of printing to the command line, when there are no output + arguments: + + im2bw + ** Deprecated functions. The following functions were deprecated in image 2.2.0 and have been
--- a/inst/im2bw.m +++ b/inst/im2bw.m @@ -59,37 +59,44 @@ if (islogical (img)) warning ("im2bw: IMG is already binary so nothing is done"); - BW = img; - return - endif + tmp = img; + + else + ## Convert img to gray scale + if (nargin == 3) + ## indexed image (we already checked that is indeed indexed earlier) + img = ind2gray (img, cmap); + elseif (isrgb (img)) + img = rgb2gray (img); + else + ## Everything else, we do nothing, no matter how many dimensions + endif - ## Convert img to gray scale - if (nargin == 3) - ## indexed image (we already checked that is indeed indexed earlier) - img = ind2gray (img, cmap); - elseif (isrgb (img)) - img = rgb2gray (img); - else - ## Everything else, we do nothing, no matter how many dimensions + ## Convert the threshold value to same image class to do the thresholding which + ## is faster than converting the image to double and keep the threshold value + switch (class (img)) + case {"double", "single", "logical"} + ## do nothing + case {"uint8"} + thres = im2uint8 (thres); + case {"uint16"} + thres = im2uint16 (thres); + case {"int16"} + thres = im2int16 (thres); + otherwise + ## we should have never got here in the first place anyway + error("im2bw: unsupported image class"); + endswitch + + tmp = (img > thres); # matlab compatible (not "greater than or equal") endif - ## Convert the threshold value to same image class to do the thresholding which - ## is faster than converting the image to double and keep the threshold value - switch (class (img)) - case {"double", "single"} - ## do nothing - case {"uint8"} - thres = im2uint8 (thres); - case {"uint16"} - thres = im2uint16 (thres); - case {"int16"} - thres = im2int16 (thres); - otherwise - ## we should have never got here in the first place anyway - error("im2bw: unsupported image class"); - endswitch + if (nargout > 0) + BW = tmp; + else + imshow (tmp); + endif - BW = (img > thres); # matlab compatible (not "greater than or equal") endfunction %!assert(im2bw ([0 0.4 0.5 0.6 1], 0.5), logical([0 0 0 1 1])); # basic usage