How can I read image metadata from binary blobs? - coldfusion

I have some images (in PNG and JPG format), stored as blobs in the database. I am retrieving them with a query and would like to take action by reading the metadata without writing the image to disk.
I am looking for the file type and image width.

You should be abe to convert the data to a ColdFusion Image type using the ImageNew function as documented here (set the source to be the variable you pulled out of the query).
Once you have the image, you can use the ImageInfo function to retrieve image properties.
This will give you the width. CF won't tell you the original file format, though--it might be easiest to look at magic numbers for that. Wikipedia gives a good summary of what those are and what the values for jpeg and png are: http://en.wikipedia.org/wiki/Magic_number_(programming)

Related

Writing image data to the disk as fast as possible

I am writing an application that generates a huge amount of images. Each frame is 1280x800 pixels large and has 1 byte per pixel for color information (greyscale). Each of the frames must be written to disk.
Currently I simply dump the raw pixel data to a binary file on the disk. The file can then be viewed with a special viewer I also created.
This is a very unsatisfactory solution, since the images can't be viewed/processed directly. They always have to run through my custom viewer/converter.
Is there an image format I could use to write my images to disk that:
Is fast to be written (no compression etc.)
Does not increase the final file's size much
Supports dumping my raw pixel buffer in there (no alignemnt changes etc.)
Can be read by common applications (Windows Explorer, Paint, Photoshop etc.)
I already tried to use .png, but the file generation takes much too long due to the compression.
Have a look at the binary Portable GrayMap (P5) format. It consists of an extremely simple header followed by raw image data (without any alignment requirements), and is widely supported by image viewers.
Both bmp and tiff can be used to save raw data. Bmp has the oddity of having image upside down, unless height is negative. And tiff has plenty of encoding options. It should be anyway feasible to reverse engineer the format to be used as a template, where the image data is copy pasted. So no need to use a library: just a header, image data and an optional footer concatenated.

How i can extract PIXEL from DICOM file?

I want to write a script to extract the PixelDATA of a DICOM file using c or c ++, I don't want to use external libraries like dicomsdl... if anyone can help me to write algorithm for extract and show image .
Just extracting the image data under the pixel data is not enough to interpret the DICOM image properly. You will need other attributes from DICOM file such as Rows, Columns, Bit Allocated, Bit Stored, High Bit, Photometric Interpretation, Sample Per Pixel to Number of Frames information just to interpret the raw uncompressed image data. Also, stored image data can be in Little Endian or Big Endian byte order. In addition, image data can be encapsulated or compressed (e.g. compressed using different compression algorithms such as JPEG, JPEG 2000, JPEG LS, RLE etc)) and compressed streams are stored differently than the uncompressed image data. Even the PixelData element can exist in multiple locations in a single DICOM file (e.g. one under the Icon Image Sequence (thumbnail) and one at the top level (actual image).
It can get more complicated when you need to account for Palette Color (segmented vs un-segmented), modality LUT, VOI LUT etc. My recommendation is to use an existing DICOM SDK and there are many open source and commercial SDK available for different platforms and programming environments.

Decryption not working on a saved image but works on the pixel manipulated matrix of the image

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

How do I create a QIcon from binary data?

I have a custom file format which stores some images. I load these images into memory during the operation of my program. The images are loaded in binary format (i.e. the same way they would appear on disk). I know what format the images are in (pretty much all jpeg). The problem is that I dont know the width/height, but I want to display the images without writing them to some temp file on disk. Anyone know how to do this?
You can get the size of a qIcon using actual size
http://qt-project.org/doc/qt-5.0/qicon.html#actualSize
You shouldn't have to write anything to disk, you just need to read your binary into something like QIcon, so that you can use QTs methods to get the width and height of the image. You just need to get the data into one of QTs data structures.
Check out QImage and QPixmap, I think they have methods for reading in binary. Or you can check this SO post here: QImage from unsigned char buffer (jpg format)

Save a raw image in OpenCV

I'm trying to use OpenCV to read/write images for me. Currently, I have them in a different, non-standard format, and I know how to get them into OpenCV's containers. Here are the requirements:
The pixels are 1, or 3 bands, U8, U16, U32, or F32
The images have metadata, random stuff, like the camera ID that took the images. I would like the metadata to be vi/notepad editable
I want to write as little code as possible when it comes to low level stuff. My experience is that this stuff requires the most maintenance.
I can define the format. It's only to read and write for these programs.
I don't want the pixels to be anything but binary, '0.5873499082' is way too much data for one float.
Is there a way to describe to OpenCV how to read and write image types it doesn't know? Are there image types already available for the types of images I have?
My interim solution is to use boost to serialize the image, and save the metadata in a separate file.
Try using gdal library for reading images and then convert it to IplImage.
OpenCV can't do that for you, you can store the metadata in a separate file, or you can use for example the jpeg exif (that won't be notepad editable though).