Post Reply 

How to extract RGB pixel data from jpg?

Dec 7, 2011, 08:36
Post: #1
How to extract RGB pixel data from jpg?
I am trying to take a jpg file of an image, and write each RGB pixel color's value into a 3 component integer vector corresponding to the RGB components of the color for that pixel. For each pixel in the jpg, I wish to write the corresponding 3 by 1 integer vector into a matrix after which I plan to do a SVD decomposition of the newly constructed matrix to do an image analysis.

Does anyone know of a plug-in that allows one to efficiently iterate through each pixel in a jpg, and convert the pixel data to a RGB integer vector, and say write to a file?

Thanks for any guidance you may provide!

Specific Details:
I am using gimp 2.6 as my image editor, and wish to collect all the RGB 3 by 1 integer vectors (where each 3 by 1 integer vector corresponds to RGB color of exactly one pixel in the jpg image) into a matrix of integer so that I can do a reduced SVD decomposition of that matrix to analyse the pixel data: I wish to compare two similar images by using the SVD decomposition of integer matrices corresponding to the two images saved as jpg files pic1.jpg and pic2.jpg.
Find all posts by this user
Quote this message in a reply
Dec 7, 2011, 08:52 (This post was last modified: Dec 7, 2011 09:02 by ofnuts.)
Post: #2
RE: How to extract RGB pixel data from jpg?
Gimp can save images in very many formats ("File/Save as...") that are easily decoded, either text-based (XPM, C source code or other) or simple-minded uncompressed binary bitmaps (BMP, TGA, and some others).

You can also use a command line tool to convert image from JPEG to these formats, such as Imagemagick's "convert" utility.

And you'll also find libraries to load JPEGs into arrays directly (all Linux systems have a "libjpeg" library usable at least from C/C++, and Java language runtimes come with one). Since the Linux lib is open source you'll find it ported to other systems.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Dec 7, 2011, 10:05
Post: #3
RE: How to extract RGB pixel data from jpg?
I don't know of any gimp plugin but you can get a result using ImageMagick

the command convert file.jpg file.txt dumps a listing of pixel values.

a little test example here. http://i.imgur.com/0D0m7.jpg

Might get you on your way.
Note the colour shift for the jpg. The bmp had a limited palette and did not convert very well as a jpg.

** https://www.gimp-forum.net/ now answering questions**
Find all posts by this user
Quote this message in a reply
Dec 7, 2011, 20:12
Post: #4
RE: How to extract RGB pixel data from jpg?
(Dec 7, 2011 10:05)rich2005 Wrote:  I don't know of any gimp plugin but you can get a result using ImageMagick

the command convert file.jpg file.txt dumps a listing of pixel values.

a little test example here. http://i.imgur.com/0D0m7.jpg

Might get you on your way.
Note the colour shift for the jpg. The bmp had a limited palette and did not convert very well as a jpg.

Hi, Thanks! That worked perfectly! I really appreciate your help on that!

Thanks for your guys help!
Find all posts by this user
Quote this message in a reply
Dec 7, 2011, 20:22
Post: #5
RE: How to extract RGB pixel data from jpg?
(Dec 7, 2011 08:52)ofnuts Wrote:  Gimp can save images in very many formats ("File/Save as...") that are easily decoded, either text-based (XPM, C source code or other) or simple-minded uncompressed binary bitmaps (BMP, TGA, and some others).

You can also use a command line tool to convert image from JPEG to these formats, such as Imagemagick's "convert" utility.

And you'll also find libraries to load JPEGs into arrays directly (all Linux systems have a "libjpeg" library usable at least from C/C++, and Java language runtimes come with one). Since the Linux lib is open source you'll find it ported to other systems.

Hi thanks for your help! I will explore those libraries: being able to write the JPEGs directly into an array would be convenient as an SVD decomposition could be done directly on that array.
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How to paint with single pixel? Teekin 3 309 Sep 28, 2014 16:00
Last Post: rich2005
  is saving as JPG safe enough ? kenny1999 2 199 Sep 25, 2014 00:14
Last Post: kenny1999
  Changing xcf files to jpg blaumann 3 254 Aug 19, 2014 20:28
Last Post: paynekj
  How Do I Add One Pixel Dots to a TGA Image? jagdpanther 3 244 Aug 17, 2014 01:12
Last Post: fluffybunny2
  Saving file as jpg labladylori 1 306 Jul 8, 2014 18:21
Last Post: rich2005

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS