On either TurboJpeg or the underlying libJpeg APIs - is there a simple function for extracting the Y component from the Ycbcr (after I've already read the image)?
I know I can loop over the data and extract the bytes. Isn't this already implemented?
When decompressing/decoding, use the TJPF_GRAY format, it discards the colour information and only the Y (luminescence) remains.
See the this part of the API for reference, as well as that part if you are willing to transform it, or this function if you are willing to decode it directly into a gray-scale image.
Related
A very beginner in OpenCV
I am trying to implement text steganography: Trying to hide a text message in an image.
What I do is, I hide each of the characters from the text message by modifying the pixels in the image. For each of the characters I take the binary representation of the character and replace the last bit of a pixel with the LSB of the character, and gain last bit of another pixel with the 2nd bit of the character, and so on .... for the whole message.
After this encryption of the text into the image I store it on the disk using cv::imwrite.
This image is again read in by another routine and decrypts it doing the reverse opeartions used for encrypting.
But, the problem is decryption is not working if i read in the image(encrypted image) whihc is stored using cv::imwrite.
But, it works if I pass-on the encrypted matrix (cv::Mat) object to the decryption routine rather than reading a image again.
Seems, something is getting changed when i store the encrypted matrix into an image.
Not sure what is going on behind the scenes. Any help is appreciated.
It sounds like you loose the information when saving.
According to the documentation of imwrite function ( imwrite() documentation ) the function chooses the format of the image based on the extension of the filename you are giving. Could it be that you are using a lossy file format such as JPEG (*.jpg)? instead try using a .png which uses a lossless compression to save the data.
EDIT:
You can use different approach for steganography specially designed for jpeg images: http://www.sav.sk/journals/uploads/0317153109jo-mo.pdf
I'm trying to get a YUV420 palanar or semiplanar (NV12) image out of jpeg using libjpeg.
I see that there is a option to specify output format to JCS_YCbCr which would generally be a YUV format, but as far as i understand it would give me the data as arrays of 3 elements { Y, U, V }. So to get the image to the right format i would have to rearange and subsample the pixels myself and i want to avoid that for performance reasons.
So I was wondering is there a way to configure libjpeg to output a YUV420p / NV12 buffer directly.
Just take a look at gst_jpeg_decode() in gstreamer source tree. This function along with gst_jpeg_decode_direct() function does exactly what you want to do.
Note that it gives YUV420 planar output, bypassing all color conversion done by libjpeg. (Note: this assumes that the input JPEG is encoded in YUV420 color space (aka I420), which is true for almost all JPEGs out there.
Is it possible to:
read an image given by just a filename (not knowing the image format) to a 2d matrix rgb uncompressed form (e.g. read an JPG to a 2d array)
access the bytes of that image, copy them, change them... (e.g. inverse the colors, I need a pointer to the image bytes, setters/getters won't do )
save those bytes to any given image format (e.g. save the inversed image to PNG)
Is it possible with boost::gil ? Maybe there is a different library more appropriate for such a task?
Sample code would be highly appreciated.
Yes, you can do all that in boost::gil.
What you should know though, is that boost::gil is only a universal interface and doesn't handle reading/writing images all by itself. You still need to use a second library, e.g. libpng..
Yes, yes and yes.
There are functions that enable you to read and write JPEG, TIFF and PNG images: see here.
For the second bullet, it is what just GIL is meant to do. You can manipulate images using its facilities (click here).
If not, where can I find the algorithm to adjust contrast of an image. I will have to code it in C++ and have access to libjpeg and libjpeg-turbo libraries
http://en.wikipedia.org/wiki/Image_editing#Contrast_change_and_brightening
Is this a good starting point for color images?
The simplest I could have think of is the ImageMagick library, or do it yourself*.
* I know that the code in that answer is not c++, but if you know c or c++, you should be able to understand it.
You might like this one for starters: Processing in the 8-bit YUV Color Space
C there is the contrast adjustment. With an image with pixel format in YUV color space, constrast adjustment is quite easy and is an update for Y component of the pixel.
libjpeg is not quite the tool for image processing, unless you are decoding/encoding JPEGs and you need some processing on the way.
I'm building a program to convert an image file (whatever file type would be easiest) to G-Code for use on a rep-rap with a pen plotter attachment.
I'm wondering if i wanted to process the image pixel by pixel and check things like pixel color, how could I do this with C++?
I would really like to know how I can process a bitmap image, pixel by pixel, to check the color of the pixel.
The best way is to use a library, like for example Magick++.
When you load an image, you can access it's pixels data with Blob
You will probably want to use an existing library that has been tested.
But for fun/practice/etc, this would be a good exercise and wouldn't be impossible to do. The Bitmap Format is (relatively) simple compared with other image formats. The Wikipedia page has some tons of info, including some C++ code. It looks like once you've gotten past the header information, you get to a pixel array that shouldn't be difficult to parse.
Good luck.
Most image formats consist of a header and the actual raw image data. A bimpap image is no different. If you don't want to use one of the existing libraries, or if you are not allowed to, you should read about bitmap format :
http://en.wikipedia.org/wiki/BMP_file_format
Once you understand this you could create appropriate structs/classes to store the information you want from the header such as x,y size, bpp etc. And also have a pointer to the raw image data. You could then simpy iterate through every pixel and do whatever you want with it :)
Once you decipher the image file, I suggest you place the pixels into a matrix, for the first pass. (Future revisions can use other methods to access the pixels).
You can apply transformations to the pixels by using matrix multiplication. You can also access the pixels individually by using array indexing.
Search the web and SO for "introduction to graphics c++".