0

I have some project wherein I have to manipulate some raw data from an image generated. But, the problem is that the image being created is in .jpeg format and I have no idea as to how to extract the raw data from it.

I am working on a project on MAC OS and thus, to talk to Apple APIs, Objective-C is being used.

Can anyone suggest some techniques or some Apple APIs, if possible, which can assist me in extracting the desired from the image?

Sankalp
  • 2,709
  • 2
  • 26
  • 40
  • What kind of operation do you want to do with the raw data. Do you want to apply filters or something and want to access individual pixel information? Please elaborate a little on the nature of your task. – SayeedHussain Sep 26 '13 at 07:16
  • Just some information like number of pixels, number of color components, no. of bits used per pixel, etc. – Sankalp Sep 26 '13 at 07:21
  • Check this -> http://stackoverflow.com/questions/448125/how-to-get-pixel-data-from-a-uiimage-cocoa-touch-or-cgimage-core-graphics. Also, I would like to add that it is easy to find out the number of pixels by finding out the height and width of the image and multiplying them. Typically each raw pixel should be 4 bytes(1 byte for R value (0-255), 1 for Green, 1 for Red and 1 for alpha). But you may find that the JPEG format will give you a much less file size than what you would get by simply multiplying no.of pixels by 4 bytes and that's because it uses lossy optimizations. – SayeedHussain Sep 26 '13 at 07:36
  • @paranoidcoder Thanks for the info! But, the problem is that I cannot assume anything as for this project. I "have to" get the confirmed data from the image as to what are the number of bits per pixel and other pixel specific informations. If, as you are saying, jpeg is a lossy compression, then, I guess I'll have to try to generate some other format like .tiff – Sankalp Sep 26 '13 at 08:17
  • Also, I would like to add one more thing- I only have the image location and do not have the `UIImage` as mentioned in the link you referred to. – Sankalp Sep 26 '13 at 08:20
  • If you have the image location i.e. I am assuming image url, you can download the image from that url. So I think it will depend on the format of the image that the url is referring to. It could be jpg, png or tiff or any other image format. Remember that if the url is pointing to a jpg, I doubt that by converting this jpg file to png, you would be able to get information about the original image because when the original image was saved as jpg, it lost some information because jpg is lossy. I doubt you can go from this lossy jpg to original data by just generating a png from the lossy jpg. – SayeedHussain Sep 26 '13 at 10:43
  • Image compression is either lossy, non-lossy. png is non-lossy compression so you can access original image data. jpg is lossy compression. http://stackoverflow.com/questions/419584/what-is-the-difference-between-jpg-jpeg-png-bmp-gif-tiff-i – SayeedHussain Sep 26 '13 at 10:49
  • Thanks for the info! So, I guess there is no reliable way to extract the required info from the .jpeg format since it's `lossy`. – Sankalp Sep 26 '13 at 10:52
  • You can probably read what the jpg contains but nothing much about the original image. I am also not very initiated into this topic. You need to refer some other sources too. I am simply drawing parellels between image processing and audio processing. I am somewhat familiar with audio processing. – SayeedHussain Sep 26 '13 at 17:51

1 Answers1

0

[[NSData dataWithContentsOfFile:<your file path>] bytes] will give you char* pointer to the raw bytes of the file. You can parse them according to JPEG spec (which should be easy to google up).

Alim
  • 46
  • 7