How to convert a matrix containing a non-demosaiced image to a RAW image file, openable by Lightroom? - image

I have a camera module, from which I am reading out "RAW", non-demosaiced image data (this camera module uses a Bayer BGGR filter). I am currently storing this in a MATLAB matrix. I am aware that MATLAB can demosaic this image for me, but I would like to use Adobe Lightroom's demosaicing algorithm and processing tools.
Do any tools exist to convert this matrix (using MATLAB or otherwise) into a standard RAW file, such as Adobe's DNG format? I understand that DNG is very similar to TIFF, can this be leveraged?

As I know, you can use the Adobe DNG SDK. Download Adobe DNG SDK from here.
Adboe DNG SDK can read dng format and save dng as tif format.
If you want to read bayer format( non-demosaiced image data ), you can try to hack Adobe DNG SDK. Replace of bayer data before demosaic.
Something need to notice.
You must use correct "bayer type"( BGGR , RGGB.. etc ).
You must use correct "bits per sample".
You must use correct "width" and "height".

Related

How to create raw synthethic images

I want to perform the color calibration of my camera. That's why I search demosaic algorithm, which can provide the closest color to color of a real object. That's why I want:
create synthetic images in OpenCV with known colors
mosaic it
pass it in an algorithm for estimation of efficiency
I use libraw for unpacking raw images and OpenCV for processing and storing them.
So, the question is, is there a library that can provide me different demosaic algorithms(i am ready to convert my synthetic image from Mat to C-style array) where I can pass my mosaic image and receive demosaic image. I think that it is possible to convert my image from tiff to dng and use RawTherapee for demosaicing, but it looks more complicated.
I solved that problem by using dng sdk.
Pipeline for using class from link in the end of answer is here:
DngCreator creator;
cv::Mat mosaic = //some method that returns Bayer RGGB mosaic
creator.BuildDngImage(mosaic);
creator.setCameraProfile();
creator.setExifTags();
creator.setXmp();
creator.setMosaicInfo();
creator.WriteDng("output.dng");
As it can be seen i used opencv for creating mosaic images
There is source code with class DngCreator, which writes the simplest dng. I didn't make good dng with all needed tags, but RawTherapee red my dng successfully.
The cite to code: https://pastebin.com/M4GRBfUG

Converting png / jpg images to svs / tif image format

How can I convert png or jpg image files to svs or tif Aperio image formats? It can be in python, c++, c# or java.
Is there any library that support tif or svs format?
I think that this conversion is impossible since SVS constitutes a proprietary format. Openslide implements the logic to read SVS streams, but the same is not true for writing them as the specification is not open-source.
A possible workaround can be found in this blog post which explains how to write an image with the minimum set of attributes that the Openslide reader method expects to sucessfully execute.

Extract a whole scale image from a SVS format file in C++

I am trying to extract a whole scale image from a SVS file in C++.
I saw an explanation from the OpenSlide homepage.
It says the SVS format is "single-file pyramidal tiled TIFF".
So I tried to extract a whole-scale image like I did for TIFF image: I read all IFDs from the SVS file, but there is no 273 tag which contains an address pointing to a whole scale image.
That's why I am little confused now, the SVS format doesn't have a whole scale image inside the file?
I found an undefined private tag from a SVS file which number is 34675. Is this tag is for a whole scale image?
Or is there a proper way to extract it?
Aperio SVS is a tiled format. All levels of the pyramid are tiled images. The base layer is the first TIFF directory. This page of the LibTiff documentation shows how to read tiled images.
In short, you need to look for tag 324 (TIFFTAG_TILEOFFSETS), as well as tags 322 and 323 (TIFFTAG_TILEWIDTH, TIFFTAG_TILELENGTH). I highly recommend you use LibTiff for this, and don’t try to roll your own.
The custom tag in the SVS file contains metadata, including the physical size of a pixel in micron (SVS doesn’t set the resolution TIFF tags).
You can read out the thumbnail image (is this what you mean by whole scale image?) as an openslide associated image.
For example, libvips has a convenient openslide binding written by the openslide authors:
$ vipsheader -f slide-associated-images CMU-1.svs
label, macro, thumbnail
Lists the images in the SVS file. macro is the huge pyramid that you get by default, thumbnail is the small overview, label is the shot of the slide label.
Get the thumbnail like this:
$ vips copy CMU-1.svs[associated=thumbnail] x.jpg
To read as a JPG image.
In C++, you could write:
VImage thumb = VImage::new_from_file("CMU-1.svs",
VImage::option()->set("associated", "thumbnail"));
thumb.write_to_file("x.jpg");

Uncrush PNG image on ubuntu?

IPA image uses pngcrush to compress PNG image, but I want to uncrush a PNG image on Ubuntu.
Can anyone give me any idea?
The standard PNG utility pngcrush has been modified by Apple, which makes it produce technically invalid PNGs: a new chunk is inserted before the mandatory first chunk IHDR, RGB(A) order of pixel data is inverted, and RGB pixels get premultiplied with their alpha.
Hence, I'd rather call these PNGs "fried", rather than just "crushed".
Try my own pngdefry. The source code is written on a Mac OSX machine but it should be compilable for other OSes as well; it's pretty straightforward C code.

TIFF image file format

I am working on TIFF images for image compression.
I want to know how is the actual raw image data i.e. R,G,B components organised/stored in the TIFF file.
Is it stored as G0B0R0G1B1R1... (1 byte each for each color component, all components intereleaved)
or is it some other way viz. planar format or something else?
Thank you.
-AD.
TIFF specifies:
How attributes are associated with a page
How multiple pages (and their attributes) are packed into a single file
Page attributes include properties such as:
Dimensions
Encoding scheme
In other words, a TIFF file may contain data that's encoding using any of many different encoding schemes.
The TIFF file can store various image types:
Bilevel (B/W)
Grayscale
Palette-color
RGB full-color
The storing of actual image data is done differently for each image type.
The specification is not the scariest I have seen, but it is definitely not trivial!
The TIFF specification can be found here: http://partners.adobe.com/public/developer/tiff/index.html
I have been doing the same, with tiff files looking at multi resoution tiffs.
Adobe have TIFF 6 documentation on their website.
You should be able to use P/Invoke on LibTiff with c# or vb.net.
Their are many types of compression, some of them proprietary.
Looking at the doc supplied by tomassao, I see that uncompressed RGB is just one of the possible tiff encodings.
It looks like the data is not interleaved. In fact, you can specify more than 3 samples per pixels (but RGB is 3), and you can specify different numbers of bits per sample (but 8,8,8 is common).
I assume you already know about how the headers work. The document covers it if you don't.

Resources