From owner-help-octave at bevo dot che dot wisc dot edu Thu Jan 30 18:08:44 1997 Subject: Re: Image Processing Toolbox From: jcardoso at inescn dot pt To: help-octave at bevo dot che dot wisc dot edu Date: Thu, 30 Jan 97 23:37:10 GMT Shahid dot Masud at ee dot qub dot ac dot uk wrote: | Hi, | | Has anybody used the image processing toolbox available from octave's | contribution archive. I tried to use it on version 1.1.1 and 2.0.2 but | to no luck. A function called "isreal" has been used in all .m files of | image toolbox but is not defined anywhere. | | If anybody has got some test images in octave format (like lena, barbara) | or infact any images, it is a good idea to make them a part of image | processing toolbox for experimentation and serious work. The image | "default.img" supplied with octave distribution is good but not enough. | Especially, if anybody has got a script to translate images in .mat or | .gif to octave's .img format, I feel it should be shared to enhance the | utility of octave in image processing. Hi, You can try the .m functions bellow. I found 'ppm' to be the best format to use with octave. No exaustive testing. On _real_ images octave is Very slow. With color images, the colormap created has as many entries as pixels in the image! No sharing... The 'saveimage' could use 'octtopnm', which is distributed in the sources, and is much faster; the source only needs a small change to work, and of course 'saveimage' needs a small change: *** saveimage.m Mon Dec 16 00:28:25 1996 --- /usr/local/share/octave/2.0.2/m/image/saveimage.m Thu Jan 30 02:17:19 1997 *************** *** 107,126 **** endif ## If we just want Octave image format, save and return. if (strcmp (img_form, "img")) eval (strcat ("save -ascii ", filename, " map img")); return; endif ## Convert to another format if requested. ! #jc: just use octtopnm! ! if (strcmp (img_form, "ppm")) ! eval (strcat ("save -ascii ", filename, ". map img")); ! system(strcat("octtopnm \"", filename, ".\" >", filename)); ! system(strcat("rm -f ", filename, ".")); ! return ! endif ! grey = all (map(:,1) == map(:,2) && map(:,1) == map (:,3)); pbm = pgm = ppm = 0; _________________________________________________________________ function gray = ppm2gray(file) # ppm2gray: raw/ascii ppm picture to gray image format # # xv-3.10a stores each header line on a separate line, \n separated # giftoppm is identical to xv # in xloadimage-4.0 there is only one header line, parameters separated by space # xwpick-2.10 also # octave... should really use 'octtopnm', its much faster for _real_ pictures... # all use P6/P3 as ppm format. fp=fopen(file,"r"); ver=fscanf(fp,"%s%*c","C"); # get version a='#'; # get rid of xv comments while (a(1,1) == '#') pos = ftell(fp); a=fgetl(fp); endwhile fseek(fp,pos); [xx yy max_c] = fscanf(fp,"%d%d%d","C"); # get number of x and y pixels if ( ver(1,2) == '6' ) # raw format a=fread(fp,[xx*3 yy],"uchar"); # read data elseif (ver(1,2) == '3' ) # ascii format a = fscanf(fp,"%d", [xx*3 yy]); else fclose(fp); error("ppm2gray: only process ascii/rawbit, P3/P6, format files") return endif r=a(1:3:xx*3,:); g=a(2:3:xx*3,:); b=a(3:3:xx*3,:); gray = (r.+g.+b)'./(3*max_c); fclose(fp); endfunction ____________________________________________________________ function [r g b] = ppm2rgb(file) # ppm2oct: raw ppm picture to gray image format # # xv-3.10a stores each header line on a separate line, \n separated # giftoppm is identical to xv # in xloadimage-4.0 there is only one header line, parameters separated by space # xwpick-2.10 also # octave ... # all use P6 as ppm format. fp=fopen(file,"r"); ver=fscanf(fp,"%s%*c","C"); # get version if ( ver(1,2) != '6' ) error("ppm2oct: only process rawbit, P6, format files") return endif a='#'; # get rid of xv comments while (a(1,1) == '#') pos = ftell(fp); a=fgetl(fp); endwhile fseek(fp,pos); [xx yy max_c] = fscanf(fp,"%d%d%d","C"); # get number of x and y pixels a=fread(fp,[xx*3 yy],"uchar"); # read data r=a(1:3:xx*3,:)'./max_c; g=a(2:3:xx*3,:)'./max_c; b=a(3:3:xx*3,:)'./max_c; fclose(fp); endfunction ____________________________________________________________ function gray = gif2gray(file) o_file = tmpnam; system(sprintf("giftoppm %s > %s",file, o_file)); gray = ppm2gray(o_file); system(sprintf("rm -f %s", o_file)); endfunction -- Joao Cardoso, INESC | e-mail: jcardoso at inescn dot pt R. Jose Falcao 110 | tel: + 351 2 2094345 4050 Porto, Portugal | fax: + 351 2 2008487 -- Joao Cardoso, INESC | e-mail: jcardoso at inescn dot pt R. Jose Falcao 110 | tel: + 351 2 2094345 4050 Porto, Portugal | fax: + 351 2 2008487