"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "macros/imshow.sci" between
sip-0.5.6.tar.gz and sip-0.12.1.tar.gz

About: SIP (Scilab Image Processing) toolbox to do imaging tasks such as filtering, blurring, edge detection, thresholding, histogram manipulation, segmentation, mathematical morphology, color image processing, etc.

imshow.sci  (sip-0.5.6):imshow.sci  (sip-0.12.1)
function imshow(img, arg2,strf) function imshow(img, arg2, strf, viewer)
// //
// Displays image in Scilab graphic window. // Displays image in Scilab graphic window.
// imshow(I) // I assumed to be 0-1 // imshow(I) // I assumed to be 0-1
// imshow(I,n) // I assumed to be 0-1 // imshow(I,n) // I assumed to be 0-1
// imshow(I,[low high]) // imshow(I,[low high])
// imshow(X,map) // X assumed to be 1-N // imshow(X,map) // X assumed to be 1-N
// imshow(RGB) // RGB 0-1 // imshow(RGB) // RGB 0-1
// imshow(RGB, arg2, [, strf, viewer]) // RGB 0-1
// imshow filename // imshow filename
// //
// AUTHOR // AUTHOR
// Ricardo Fabbri <rfabbri@(not this part) gmail d0t com> // Ricardo Fabbri <rfabbri@(not this part) gmail d0t com>
// Cybernetic Vision Research Group // Cybernetic Vision Research Group
// Luciano da Fontoura Costa, supervisor. // Luciano da Fontoura Costa, supervisor.
// http://siptoolbox.sf.net // http://siptoolbox.sf.net
// //
// TODO // TODO
// //
// - incorporate other Matplot parameters // - incorporate other Matplot parameters
// - use internal imagemagick API for 'display'-style viewer without
// writing image to disk
// //
// $Revision: 1.2 $ $Date: 2009-03-29 21:34:48 $ // $Revision: 1.2 $ $Date: 2009-03-29 21:34:48 $
[lhs, rhs] = argn(0); [lhs, rhs] = argn(0);
if rhs == 0 then if rhs == 0 then
error('Invalid number of arguments.'); error('Invalid number of arguments.');
end end
if ~exists('strf','local') if ~exists('strf','local')
strf='040' strf='040'
else else
rhs=rhs-1 rhs=rhs-1
end end
if ~exists('viewer','local')
viewer=SIPVIEWER
end
if viewer <> 'sci'
if getos() == 'Windows'
error('external viewer not supported on Windows');
else
try
tmpname = tempname();
catch
tmpname = TMPDIR + '/sip-imshow' + string(round(rand()*100000));
end
tmpname = tmpname + '-imshow.png';
// remove temp file only at the beginning
unix('rm -f ' + TMPDIR + '/*imshow.png');
end
end
// TODO // TODO
// double-buffering will be default for the next SIP release // double-buffering will be default for the next SIP release
// TODO do it the modern way as in sip-intro.dem // TODO do it the modern way as in sip-intro.dem
// //
//prev_pixmap_mode = xget('pixmap'); //prev_pixmap_mode = xget('pixmap');
// //
//// double-buffering: //// double-buffering:
//if ~exists('sip_disable_pixbuffer') //if ~exists('sip_disable_pixbuffer')
// xset('pixmap',1); // xset('pixmap',1);
//end //end
select type(img) select type(img)
case 1 then // paletted or grayscale image case 1 then // paletted or grayscale image
if rhs == 1 then if ~exists('arg2','local')
[m,n]=size(img) if viewer == 'sci'
xset('colormap', graycolormap(256)) [m,n]=size(img)
xset('wdim',n,m) xset('colormap', graycolormap(256))
Matplot(img*255 + 1,strf) try
set(gcf(), 'axes_size', [n m]);
set(gca(), 'tight_limits','on')
catch
xset('wdim',n,m)
end
Matplot(img*255 + 1,strf)
else
if sip_get_verbose() == 'wordy'
disp ('writing temporary image file ' + tmpname );
end
imwrite(img, tmpname);
end
else else
[m2,n2] = size(arg2) [m2,n2] = size(arg2)
[m,n]=size(img) [m,n]=size(img)
if n2 == 1 then if n2 == 1 then
if type(arg2) ~= 1 then // imshow(img,ncolors) if type(arg2) ~= 1 then // imshow(img,ncolors)
error("2nd argument must be a scalar.") error("2nd argument must be a scalar.")
end end
if (arg2 < 3) if (arg2 < 3) // workaround to a colormap bug
xset('colormap', [0 0 0; 1 1 1]) mygraycmap = [0 0 0; 1 1 1];
else else
xset('colormap', graycolormap(arg2)) mygraycmap = graycolormap(arg2);
end end
img = img*(arg2-1)+1; img = img*(arg2-1)+1;
if viewer == 'sci'
xset('colormap', mygraycmap);
else
if sip_get_verbose() == 'wordy'
disp ('writing temporary image file ' + tmpname );
end
imwrite(img, mygraycmap, tmpname);
end
elseif (n2==0 | n2==2) then // [] or [n1 n2] elseif (n2==0 | n2==2) then // [] or [n1 n2]
if n2~=0 then if n2~=0 then
img(img<=arg2(1))=arg2(1) img(img<=arg2(1))=arg2(1)
img(img>=arg2(2))=arg2(2) img(img>=arg2(2))=arg2(2)
end end
img=round(normal(img,256,1)); if viewer == 'sci'
xset('colormap', graycolormap(256)) img=round(normal(img,256,1));
xset('colormap', graycolormap(256))
else
img=normal(img);
if sip_get_verbose() == 'wordy'
disp ('writing temporary image file ' + tmpname );
end
imwrite(img, tmpname);
end
elseif (n2 == 3) then // imshow(img,map) elseif (n2 == 3) then // imshow(img,map)
if m2 == 65536 if viewer == 'sci'
// if m2 == 65536
// Scilab reserves black & white colors, so only max 65534 //
// entries are permited in the colormap :-( // Scilab reserves black & white colors, so only max 65534
// Black and white are always accessible by m2+1 and m2+2, // entries are permited in the colormap :-(
// respectively, no matter what is the current colormap. // Black and white are always accessible by m2+1 and m2+2,
// // respectively, no matter what is the current colormap.
// I'm ashamed of this code... we must urgently improve scilab's //
// image display. Please help us if you can :-) // I'm ashamed of this code... we must urgently improve scilab'
// s
img2 = ind2rgb(img,arg2); // image display. Please help us if you can :-)
arg2=sip_approx_true_cmap(11) // 11 levels (11^3 colors) //
img=sip_index_true_cmap(img2,11) img2 = ind2rgb(img,arg2);
arg2=sip_approx_true_cmap(11) // 11 levels (11^3 colors)
img=sip_index_true_cmap(img2,11)
end
xset('colormap', arg2)
else
if sip_get_verbose() == 'wordy'
disp ('writing temporary image file ' + tmpname );
end
imwrite(img, arg2, tmpname);
end end
xset('colormap', arg2)
else else
error('Invalid size of 2nd argument.') error('Invalid size of 2nd argument.')
end end
xset('wdim',n,m) try
set(gcf(), 'axes_size', [n m]);
set(gca(), 'tight_limits','on')
catch
xset('wdim',n,m)
end
Matplot(img,strf) Matplot(img,strf)
end end
case 17 then // truecolor image case 17 then // truecolor image
dims=size(img) dims=size(img)
if dims(3) ~= 3 then if dims(3) ~= 3 then
error('RGB image must have 3rd dimension equal to 3.') error('RGB image must have 3rd dimension equal to 3.')
end end
// The following works, at the cost of reduction if viewer == 'sci'
// of the number of colors to 40^3 ~= 2^16 // The following works, at the cost of reduction
// Scilab unfortunately doesn't work with 25bit colordepth // of the number of colors to 40^3 ~= 2^16
// My thanks to Bruno Pincon // Scilab unfortunately doesn't work with 25bit colordepth
printf('This may take a while.'); // My thanks to Bruno Pincon
if argn(2) == 1 printf('This may take a while.');
nlevels = 11 // 11^3 colors only, for speed if argn(2) == 1
nlevels = 20 // 20^3 colors only, for speed
else
nlevels = arg2
end
xset('colormap',sip_approx_true_cmap(nlevels))
try
set(gcf(), 'axes_size', [dims(2) dims(1)]);
set(gca(), 'tight_limits','on')
catch
xset('wdim',n,m)
end
Matplot(sip_index_true_cmap(img,nlevels),strf)
else else
nlevels = arg2 if sip_get_verbose() == 'wordy'
disp ('writing temporary image file ' + tmpname );
end
imwrite(img, tmpname);
end end
xset('colormap',sip_approx_true_cmap(nlevels))
xset('wdim',dims(2),dims(1))
Matplot(sip_index_true_cmap(img,nlevels),strf)
case 10 then // filename case 10 then // filename
map=0; if viewer == 'sci'
[image,map] = imread(img) map=0;
imshow(image,map) [image,map] = imread(img)
imshow(image,map)
else
tmpname = img;
end
else else
error('1st argument of invalid type.') error('1st argument of invalid type.')
end end
if xget('pixmap') == 1, xset('wshow'), end // if xget('pixmap') == 1, xset('wshow'), end
// Part of double-buffer default for next release: // Part of double-buffer default for next release:
//xset('pixmap',prev_pixmap_mode); //xset('pixmap',prev_pixmap_mode);
// //
if viewer <> 'sci'
mycmd = viewer + ' ' + tmpname + ' &';
if sip_get_verbose() == 'wordy'
disp ('running viewer command: ' + mycmd);
end
unix_w(mycmd);
end
endfunction endfunction
// //
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// SIP - Scilab Image Processing toolbox // SIP - Scilab Image Processing toolbox
// Copyright (C) 2002-2009 Ricardo Fabbri // Copyright (C) 2002-2009 Ricardo Fabbri
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
 End of changes. 18 change blocks. 
41 lines changed or deleted 127 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS