Image to numeric array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dimitrios Charitatos

    #1

    Image to numeric array

    Hello,

    I suspect that there is a quite straight forward answer to this, but I can't
    find it... I want to import an image and extract a matrix (or array) from it
    with elements showing the RGB value of each pixel. But I want to be able to do
    this with all types of image formats. It was suggested that a function such as
    'B = numeric.from_im age(A)' was used but I can't find it in any of the
    libraries. I was hoping you could help me on this.

    Thank you,
    Dimitris

  • Diez B. Roggisch

    #2
    Re: Image to numeric array

    Dimitrios Charitatos wrote:
    [color=blue]
    > Hello,
    >
    > I suspect that there is a quite straight forward answer to this, but I
    > can't find it... I want to import an image and extract a matrix (or array)
    > from it with elements showing the RGB value of each pixel. But I want to
    > be able to do this with all types of image formats. It was suggested that
    > a function such as 'B = numeric.from_im age(A)' was used but I can't find
    > it in any of the libraries. I was hoping you could help me on this.[/color]

    You have to install the numeric library for that. Googling numeric python
    will bring you there pretty quick.

    Diez

    Comment

    • Claudio Grondi

      #3
      Re: Image to numeric array

      Diez B. Roggisch wrote:[color=blue]
      > Dimitrios Charitatos wrote:
      >
      >[color=green]
      >>Hello,
      >>
      >>I suspect that there is a quite straight forward answer to this, but I
      >>can't find it... I want to import an image and extract a matrix (or array)
      >>from it with elements showing the RGB value of each pixel. But I want to
      >>be able to do this with all types of image formats. It was suggested that
      >>a function such as 'B = numeric.from_im age(A)' was used but I can't find
      >>it in any of the libraries. I was hoping you could help me on this.[/color]
      >
      >
      > You have to install the numeric library for that. Googling numeric python
      > will bring you there pretty quick.
      >
      > Diez[/color]
      Is there a difference between the 'Numeric' and 'numeric' module?
      I have on my system only Numeric... And this has no function like
      'from_image'.

      The usual way of doing such things is to use PIL (Python Image Library)
      to load the image from file, then export it from PIL to a Python string
      in order to import from this string to an array of the targeted
      numerical module.

      Really curious if there is a direct way in any of the numerical
      packages, as it would save the time and effort of unnecessary
      conversions from PIL, ImageMagick or from other image libraries.

      Claudio


      Comment

      • Diez B. Roggisch

        #4
        Re: Image to numeric array

        > Is there a difference between the 'Numeric' and 'numeric' module?[color=blue]
        > I have on my system only Numeric... And this has no function like
        > 'from_image'.[/color]

        I actually didn't check that - I just wanted to point the OP to the
        numeric-module(s) available, as he suggested that
        [color=blue]
        >The usual way of doing such things is to use PIL (Python Image Library)
        >to load the image from file, then export it from PIL to a Python string
        >in order to import from this string to an array of the targeted
        >numerical module.[/color]

        I'd go for the getdata() method instead.
        [color=blue]
        >Really curious if there is a direct way in any of the numerical
        >packages, as it would save the time and effort of unnecessary
        >conversions from PIL, ImageMagick or from other image libraries.[/color]

        Whatever module is capable of converting needs to know how to read images -
        either by itself, or by means of another module.


        I know for sure that pygame supports retrieving pixel-data as array.

        Diez

        Comment

        • Claudio Grondi

          #5
          Re: Image to numeric array

          Diez B. Roggisch wrote:[color=blue][color=green]
          >>Is there a difference between the 'Numeric' and 'numeric' module?
          >>I have on my system only Numeric... And this has no function like
          >>'from_image '.[/color]
          >
          >
          > I actually didn't check that - I just wanted to point the OP to the
          > numeric-module(s) available, as he suggested that
          >
          >[color=green]
          >>The usual way of doing such things is to use PIL (Python Image Library)
          >>to load the image from file, then export it from PIL to a Python string
          >>in order to import from this string to an array of the targeted
          >>numerical module.[/color]
          >
          >
          > I'd go for the getdata() method instead.[/color]
          Yes, you are right.
          Sorry, I should have checked it in source code before posting just from
          my memory. Usage of .tostring() was my first approach - I have replaced
          it later by .getdata() because of speed issues (we are speaking here
          about methods of the Image module available after installation of PIL).
          As I have experience with numarray only, I can't help here directly with
          a code example for Numeric.

          Claudio[color=blue]
          >
          >[color=green]
          >>Really curious if there is a direct way in any of the numerical
          >>packages, as it would save the time and effort of unnecessary
          >>conversions from PIL, ImageMagick or from other image libraries.[/color]
          >
          >
          > Whatever module is capable of converting needs to know how to read images -
          > either by itself, or by means of another module.
          >
          >
          > I know for sure that pygame supports retrieving pixel-data as array.
          >
          > Diez[/color]

          Comment

          Working...