"Fossies" - the Fresh Open Source Software Archive

Member "sip-0.12.1/macros/sip-intro.dem" (13 Nov 2013, 4390 Bytes) of package /linux/privat/sip-0.12.1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "sip-intro.dem": 0.5.6_vs_0.12.1.

    1 mode (-1);
    2 deff('[] = clrscr()', '')
    3 clrscr()
    4 
    5 // TODO turn on double-buffering:
    6 // Old way:
    7 //    prev_pixmap_mode = xget('pixmap');
    8 //    xset('pixmap',1);
    9 // New way (perhaps put it inside imshow):
   10 //    f = gcf();
   11 //    f.pixmap = 'on'; // double buffer mode
   12 //    show_pixmap() // send buffer to screen
   13 
   14 DIRINI = PWD
   15 chdir (SIPDIR+'images');
   16 mode (3);
   17 // 
   18 //          SIP - SCILAB IMAGE PROCESSING TOOLBOX
   19 //                    Introductory Demo
   20 //    This demo assumes your scilab window has at least 24
   21 // lines and 75 rows of text. 
   22 // Each time you see a "halt-->"  prompt, press <ENTER> to 
   23 // continue. 
   24 // To quit this demo, type <CTRL-C> followed by "abort" 
   25 // then press <ENTER>.
   26 // Please send comments to Ricardo Fabbri <rfabbri@gmail.com>
   27 //
   28 halt()
   29 clrscr()
   30 
   31 //
   32 // SIP is able to read and write image files in practically 
   33 // ANY image format.
   34 // The command
   35 // imread(filename)
   36 // reads images into Scilab matrices:
   37 [Im, map] = imread('example.bmp');    // a color image 
   38 clf
   39 imshow(Im, map);      // plots the image in scilab
   40 halt()
   41 clrscr()
   42 
   43 //
   44 // SIP can also write to image files in many formats,
   45 // including BMP, GIF, JPEG, PNG, PCX, TIFF and  XPM:
   46 //
   47 chdir(TMPDIR);
   48 imwrite(Im, map, 'Only_a_Test_Image.tif');
   49 clf
   50 halt()
   51 imshow('Only_a_Test_Image.tif');
   52 halt()
   53 chdir (SIPDIR+'images');
   54 clrscr()
   55 
   56 //
   57 //          BINARY IMAGES
   58 //
   59 //
   60 [Im] = imread('bin.xpm')   
   61 clf
   62 imshow(Im,2);
   63 f = gcf();
   64 f.figure_size = 60*size(Im);
   65 halt()
   66 // note the correspondence between the numerical entries 
   67 // and the plotted image.
   68 halt()
   69 clrscr()
   70 
   71 //
   72 //          PSEUDOCOLOR IMAGES 
   73 //
   74 //
   75 [Im, map] = imread('example.bmp');    // a color image 
   76 clf
   77 imshow(Im, map);      // plots the image in scilab
   78 halt()
   79 clrscr()
   80 
   81 // 
   82 // The way a pseudocolor image is displayed depends on 
   83 // its colormap. The command:
   84 imshow(Im,graycolormap(256));
   85 // shows Im using gray shades. Im is a standard 2D array,
   86 // with entries ranging from 1 to 256. These are indexes into
   87 // the colormap. All that was done here was to replace the 
   88 // original colormap, "map", by a grayscale one. In this
   89 // scheme, the brightness of the image is proportional to
   90 // the index.
   91 halt()
   92 clrscr()
   93 
   94 //
   95 // There are other visually interesting colormaps, used to
   96 // enhance certain features of the image. For example:
   97 //
   98 imshow(Im, hotcolormap(256)); 
   99 // where the color ranges from black (index 1) to shades of red 
  100 // and yellow to white (256)
  101 halt()
  102 clrscr()
  103 
  104 // 
  105 // A colormap is an Mx3 matrix of entries ranging from 0 to
  106 // 1 . Each column corresponds to red, green and blue color 
  107 // intensities. Each row defines a // color to be indexed by 
  108 // an  index matrix. The Scilab functions "graycolormap" and 
  109 // "hotcolormap" simply generate colormaps with the desired 
  110 // number of rows (colors). For example,
  111 
  112 Im(20,35)          // a pixel contains a colormap index
  113 halt()
  114 // the R G B intensities for that pixel (0-1):
  115 map(Im(20,35)+1, :)  
  116 halt()
  117 clrscr()
  118 
  119 // A colormap is a matrix, so it is possible to apply
  120 // operations to them, and obtain interesting visualization 
  121 // effects:
  122 cm = (hotcolormap(256) + graycolormap(256)) / 2;
  123 imshow(Im, cm)
  124 // that smoothed the chromaticity of the hot colormap.
  125 halt()
  126 imshow(Im, cm.^0.5)
  127 // that brightened the image. Since "cm" ranges from 0.0 to
  128 // 1.0, raising it to a power smaller than 1 will increase the
  129 // intensities. 
  130 halt()
  131 
  132 // Other examples:
  133 imshow(Im, 1-hotcolormap(256))    // a "cold" colormap
  134 halt()
  135 imshow(Im, 1 - map)    // inverse of the original image
  136 halt()
  137 clrscr()
  138 
  139 //
  140 //          TRUECOLOR IMAGES 
  141 //
  142 //
  143 [Im] = imread('tru.jpg');   // 'Im' is in 0-1 range
  144 clf
  145 imshow(Im);   // imshow NOW assumes 0-1 range for truecolor
  146 halt()
  147 // Truecolor images are stored as 3D hypermatrices:
  148 size(Im)
  149 Im(21,45,3)     // pixel (21,45) of blue channel
  150 halt()
  151 clrscr()
  152 
  153 //
  154 // Im(:,:,1) is the red channel array
  155 // Im(:,:,2) is the green channel
  156 // Im(:,:,3) is the blue channel
  157 //
  158 imshow(Im(:,:,2))   // shows the green channel in grayscale
  159 halt();
  160 clrscr()
  161 
  162 //       
  163 //          SIP - SCILAB IMAGE PROCESSING TOOLBOX
  164 //                       END OF DEMO       
  165 //   For more information, refer to the help pages for: imread,
  166 //   imwrite, imshow, and imfinfo functions. Also follow the
  167 //   EXAMPLE sections in the manpages of SIP functions.
  168 //    
  169 //   This demo was written by:
  170 //   Ricardo Fabbri <rfabbri@gmail.com>
  171 //
  172 halt()
  173 chdir (DIRINI);
  174 clear Im map DIRINI