[Scilab-users] An Image processing toolbox that *works*

Antoine Monmayrant antoine.monmayrant at laas.fr
Thu Jan 14 09:27:50 CET 2016


Hi everyone,

An update on the situation:

1) bug reported for IPD.
2) workaround for my workflow.

1) See: http://forge.scilab.org/index.php/p/IPD/issues/1603/
     Are the devs of IPD reading this mailing list (I know Allan used to 
read it)?
     I can give them a hand troubleshooting what's going on if they want.

2) I gave up on proper image processing in Scilab (ie with lots of bells 
and whistles) and decided to support one image format (PPM as it's a 
very simple format).
     So now, I convert all the images I need to process to PPM (using 
convert from ImageMagick) and load them in Scilab with the function below.
     (hacked in an hour, so it's far from perfect, feedback is welcome)

function img=read_ppm_file(ppm_file)
    //function to read ppm file P6 (binary RGB 8bit/channel)
    //
    // Typical file header:
    //
    //  1 P6
    //  2 389 308
    //  3 255
    //
    // Magic number P6
    // white space (here CR or LF)
    // Width whitespace Height
    // White space (here CR/LF)
    // Maximum value (here 255 mean 1 byte per pixel per channel)
    // White space
    // Height=H Width=W => H rows from top to bottom of W pixels, each 
pixel a rgb triplet, each channel on one byte if MaxVal<=255.
    //So starting from the end we should have 3*H*W bytes to read.

    //getting file size in byte
    [x, ierr] = fileinfo(ppm_file);
    file_size=x(1);
    //reading the header
    fd=mopen(ppm_file,'r');
    txt = mgetl(fd,3);// TODO : no exactly what's in the format 
specification
    mclose(fd)

    magickN=txt(1);
    maxval=eval(txt(3));

    if magickN~="P6" then
       warning("Cannot handle PPM files other than P6 (binary RGB file)");
    elseif maxval > 255 then
       warning("Cannot handle PPM files with channels encoded on more 
than 1 byte");
    else
       //good to go P6 PPM file encoded with 1 byte per channel
       //getting W & H
       tok=tokens(txt(2));
       W=eval(tok(1));//width of the image
       H=eval(tok(2));//height of the image
       //Now we need to read 3*H*W bytes from the end of the file
       bytoread=3*H*W;
       startpos=file_size-bytoread;
       fd=mopen(ppm_file,'rb');
       mseek(startpos,fd);
       dat=mgeti(bytoread,'uc',fd);//raw data
       mclose(fd);
    end
    //separating the channels
    // TODO : can we get something more elegant than transpose & reverse 
of 1st dim ?
    r=matrix(dat(1:3:$),W,H).';
    g=matrix(dat(2:3:$),W,H).';
    b=matrix(dat(3:3:$),W,H).';
    r=r($:-1:1,:);
    g=g($:-1:1,:);
    b=b($:-1:1,:);
    // building the hypermatrix from the channels
    // TODO : more elegant way to fill the image?
    img=uint8(hypermat([H,W,3]));
    img(:,:,1)=r;
    img(:,:,2)=g;
    img(:,:,3)=b;
endfunction


I hope someone might find it useful,

Antoine


Le 01/13/2016 11:20 AM, Philipp Mühlmann a écrit :
> mh, I never additionally installed OpenCV to be able to use IPD...it 
> just worked "out of the box".
>
> 2016-01-13 9:38 GMT+01:00 <amonmayr at laas.fr <mailto:amonmayr at laas.fr>>:
>
>     Le 01/13/2016 08:34 AM, CHEZE David 227480 a écrit :
>>
>>     Same conclusion for me and also question reagrding scilab 6
>>
>     Well, I use both scilab 5.5.X and 6.0.X but:
>
>     //scilab 6.0.X
>     --> atomsInstall('IPD')
>     atomsInstallList: The package IPD is not available
>
>     Antoine
>
>
>>     David
>>
>>     *De :*users [mailto:users-bounces at lists.scilab.org] *De la part
>>     de* Philipp Mühlmann
>>     *Envoyé :* mardi 12 janvier 2016 20:11
>>     *À :* Users mailing list for Scilab <users at lists.scilab.org>
>>     <mailto:users at lists.scilab.org>
>>     *Objet :* Re: [Scilab-users] An Image processing toolbox that *works*
>>
>>     Hello,
>>
>>     I've been using IPD and SIVP a lot with Scilab 5.5.1 and
>>     5.4.1...on WinXP 32 bit and Win7 64 bit.
>>
>>     Both times with IPD 8.3.2-0
>>
>>
>>     IPD would be my favourite.
>>
>>     Anybody uses IPD with Scilab 6?
>>
>>     Best regards,
>>
>>     Philipp
>>
>>
>>
>>     2016-01-12 13:43 GMT+01:00 Samuel Gougeon <sgougeon at free.fr
>>     <mailto:sgougeon at free.fr>>:
>>
>>         Hello,
>>
>>         Le 12/01/2016 12:53, antoine.monmayrant at laas.fr
>>         <mailto:antoine.monmayrant at laas.fr> a écrit :
>>
>>             Hi everyone,
>>
>>             This message is not a rant (but it could).
>>             I am truly looking for an image processing toolbox that
>>             works with current versions of Scilab and a decently
>>             modern OS.
>>             I tried every toolbox I've found but without success:
>>
>>             SIVP: requires an outdated version of libtiff that I
>>             don't know how to install on my system.
>>
>>             IPD: does not seem to work properly: ReadImage fails:
>>
>>
>>         Works for me with Scilab 5.5.2 / win7_x64 :
>>
>>             -->dir *.png
>>              ans  =
>>
>>             foo.png Google_logo.png ico.png scilab.png
>>
>>             -->atomsLoad IPD
>>
>>             Start IPD - Image Processing Design
>>                 Load macros
>>                 Load dependencies
>>                 Load gateways
>>                 Load help
>>                 Load demos
>>
>>              ans  =
>>
>>             !IPD  8.3.2-0  allusers SCI\contrib\IPD\8.3.2-0  !
>>
>>             -->i = ReadImage("Google_logo.png");
>>
>>             -->size(i)
>>              ans  =
>>
>>                 95.    275.    3.
>>
>>
>>         Do you get an error whatever is the image you try to load?
>>         You may report the error you get @
>>         <http://forge.scilab.org/index.php/p/IPD/issues/>http://forge.scilab.org/index.php/p/IPD/issues/
>>         + posting the image triggering it.
>>
>>         Cheers
>>         Samuel
>>
>>
>>         _______________________________________________
>>         users mailing list
>>         users at lists.scilab.org <mailto:users at lists.scilab.org>
>>         http://lists.scilab.org/mailman/listinfo/users
>>
>>
>>
>>
>>     -- 
>>
>>     There we have the salad.
>>
>>
>>
>>     _______________________________________________
>>     users mailing list
>>     users at lists.scilab.org <mailto:users at lists.scilab.org>
>>     http://lists.scilab.org/mailman/listinfo/users
>
>
>     -- +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Antoine
>     Monmayrant LAAS - CNRS 7 avenue du Colonel Roche BP 54200 31031
>     TOULOUSE Cedex 4 FRANCE Tel:+33 5 61 33 64 59
>     <tel:%2B33%205%2061%2033%2064%2059>email :
>     antoine.monmayrant at laas.fr <mailto:antoine.monmayrant at laas.fr>
>     permanent email : antoine.monmayrant at polytechnique.org
>     <mailto:antoine.monmayrant at polytechnique.org>
>     +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>
>     _______________________________________________
>     users mailing list
>     users at lists.scilab.org <mailto:users at lists.scilab.org>
>     http://lists.scilab.org/mailman/listinfo/users
>
>
>
>
> -- 
> There we have the salad.


-- 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++

  Antoine Monmayrant LAAS - CNRS
  7 avenue du Colonel Roche
  BP 54200
  31031 TOULOUSE Cedex 4
  FRANCE

  Tel:+33 5 61 33 64 59
  
  email : antoine.monmayrant at laas.fr
  permanent email : antoine.monmayrant at polytechnique.org

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20160114/3b4fc8f9/attachment.htm>


More information about the users mailing list