1

I have a file with the following structure:

"width" "height" "gray_levels" "pix1" "pix1_length" "pixn" "pixn_length"

Basically, I have to convert this raw data of a raster scanned image back into an image.

Also depending on the amount of gray levels used there will be different character for each gray level. My problem is that I don't really know where to begin. I know that it's better if I have a 2D array, to which I would enter the integer value of different character for the gray level. So i.e. 0 = # (and then I would enter the ASCII value of #)

fscanf(inputfile,"%i %i %i", &x, &y, &gray_levels);

This line reads the dimension of the image for later processing, but I have no idea how to use it without creating a forest i.e. like 10 loops inside one another. I think the main problem is how to program it so that e.g. when first pixel is length 300, I make it to go to the next line in the array.

Also, I shouldn't use malloc because I haven't covered that topic yet. I need to create the size of the array at runtime, so I just created an array with the maximum size of 80*100.

Jørgen R
  • 10,568
  • 7
  • 42
  • 59
machaniv
  • 91
  • 1
  • 3
  • 1
    A few points about which I would like clarifications: Is this a text file you are reading from (vs. a binary file)? What kind of image do you have to write back out? BMP, PGM? What platform/OS are you writing this on? Are there only 2 pixel runs in the file or is there an arbitrary number of pixel runs (i.e., "pix1 pix1_len pix2 pix2_len ... pixn pixn_len")? – Multimedia Mike Mar 13 '12 at 04:10
  • it is a plain text ie. 78 26 3 1 300 .. and so on It's a pseudo image. ie. made of out ASCI characters. I'm doing it on ubuntu. the number of pixels should equal to the resolution ie. 78*26 – machaniv Mar 13 '12 at 12:52
  • @user1265404: You should add that to your question. (Also, you should probably get yourself an OpenId and log in with it, lest you get "logged out" of your anonymous one, and set your nickname, so we can call you something other than user1265404.) – SamB Mar 14 '12 at 00:09
  • So it's not an actual image? Just a series of ASCII characters in a text file? Do newlines separate rows of this 'image'? – Multimedia Mike Mar 14 '12 at 22:31
  • Have a look at my answer here... http://stackoverflow.com/questions/28273627/how-to-convert-24-bit-rgb-array-into-an-image/28274754#28274754 – Mark Setchell Feb 10 '15 at 16:27

0 Answers0