SourceForge has been redesigned. Learn more.
Close

ASCII files for color images

Atidel
2008-04-01
2012-11-08
  • Atidel

    Atidel - 2008-04-01

    Hi, I am trying to convert color images contained in an image database (so big number of images) to ASCII format. I am not familiar at all with Lush. When I check the Lush manual and I try the commands, I always get errors, it never runs. Could you please explain me how to use the commands and which particular one should I use to perform my conversion. Thanks a lot. --Atidel

     
    • Atidel

      Atidel - 2008-04-07

      Dear Yann,

      I have used the (save-ascii-matrix <matrix><file> command to convert the images to .MAT3 files (what I did need) and I understood the results I got. I should not try to get .MAT2 files. However, I repeated the command as much as the number of images I have to convert; which is unpractical.

      I am trying now the method you described me. What does the command (idx-copy m (narrow :mnistdb:inputs 0 i)) exactly do ? Why to narrow the input images ?

      Thanks, ----Atidel

       
    • angelica

      angelica - 2008-04-01

      Hi Atidel,

      What commands exactly are you trying - can you paste the error? Also, are you using the online documentation or the (helptool) command? I found that the latter had more information.

      Angelica

       
    • Atidel

      Atidel - 2008-04-01

      Yes Angelica, I am using (helptool). The command I am trying is save-ascii-matrix but I am not sure this is the right one neitehr this is the right way to use it. The code I type is the following :

      (setq a "my-image-file")
      (setq b (save-ascii-matrix a)), obviously it does not run.

      ????????????

       
    • Yann LeCun

      Yann LeCun - 2008-04-01

      Atidel,

      Unless I misundertand your objective, I don't think you need to convert
      your images to ASCII.

      There is a function to read an image file (in any format) into a Lush matrix:

      (libload "libimage/image-io")

      (setq m (image-read-rgb "myimagefile.jpg"))

      m is now an NxMx3 matrix of ubytes (N = number of rows, M = number of columns).

      To read images files into a greyscale NxM matrix of ubyte you can do:

      (setq m (image-read-ubim "myimagefile.jpg"))

      Be careful that you must have installed the ImageMagick Linux
      package for this to work.

      You can now hack the dsource-mnist class and write each image into
      a slice of the input idx3. Assuming the variable mnistdb contains
      an instance of dsource-mnist, you can do

      (idx-copy m (narrow :mnistdb:inputs 0 i))

      to copy your image into the i-th element of the data source.

      -- Yann

       
    • Atidel

      Atidel - 2008-04-02

      Thank you very much Yann (merci beaucoup) for explanation. I will try what you did suggest but before I would like, as I stated earlier, to make my images on ASCII format. This choice is justified by the fact that ASCII files are machine independent which enables me to manipulate them to my liking whatever the application would be.

      I am using the (save-ascii-matrix <mat> <file>) command but I get a .MAT3 instead of .MAT2 file ! ! !

      Q1) for a color image, is this the right command to use (I get very strange results).

      Q2) for the hole image database, how can I write a batch code to generate automatically all the ASCII files.

      I just want to do this step and then try your method.

      Thanks a lot

      Atidel

       
  • Alex

    Alex - 2010-05-02

    Yann

    I tried the command: (idx-copy m (narrow :mnistdb:inputs 0 i))
    and received the following error:*** narrow : missing arguments : (o)

    Alex

     
  • Yann LeCun

    Yann LeCun - 2010-05-02

    Hi Alex,

    narrow takes 4 arguments, an idx, a dimension number (0), a size (i), and
    an offset.
    You are missing the offset. Or perhaps you meant to use select.

    • Yann
     

Log in to post a comment.