Read with 8 bits in Rmagick doesn't work correctly? - imagemagick

I have Rmagick using an ImageMagick compiled for 16bit.
However, I am able to read a file by doing this:
file = Magick::Image.read(my_file){self.depth = 8}.first
And when doing an inspect of that file, I see that it is
PNG 1400x768 1400x768+0+0 DirectClass 8-bit 333kb
However, when accessing any of the pixels, the values are bigger than 0-255.
Why is that? What am I missing?
I access it like this:
red = image.pixel_color(x,y).red
I don't understand why the value would be from 0 to 2^16, when I specifically have opened the image with 8 bits of depth.

The version of ImageMagick you are using is Q16 (16-bit). This means that ImageMagick will always use an unsigned short internally to store a channel of a pixel. You could switch to the Q8 version of ImageMagick if all your images are 8-bit. More info about the architecture of ImageMagick can be found here: http://www.imagemagick.org/script/architecture.php

Related

ImageMagick problem with identify of DNG Image without extension

I'm trying to get format, filesize, width and height from an DNG Image. With a .DNG extension identify L1004220.dng returns the correct data: L1004220.DNG DNG 5216x3472 5216x3472+0+0 16-bit sRGB 17.4867MiB 0.000u 0:00.003.
The problem now is, I've made a md5 hash from the filename and stored it somewhere else, lets call the file 17a14024496c3bea3b81362510962785. Now if I run the same command with the md5 filename it will give me another result: 17a14024496c3bea3b81362510962785 TIFF 320x216 320x216+0+0 8-bit sRGB 17.4867MiB 0.010u 0:00.008
It somehow identified it as a TIFF instead of a DNG image.
But when I give 17a14024496c3bea3b81362510962785 a .dng extension, it again works.
I only have this problem with DNG images. Other formats work as expected.
I run it on Linux. I installed the libraw-dev package which ImageMagick uses as a delegate for DNG Images. I use a self compiled ImageMagick 7.
For testing I used a sample image (Original DNG (18MB)) from here https://www.kenrockwell.com/leica/m9/sample-photos-3.htm
Anyone encountered this problem before? Am I using the wrong package as delegate?
I was able to solve the problem by adding dng: before the filename like:
identify dng:17a14024496c3bea3b81362510962785
result:
dng:17a14024496c3bea3b81362510962785=>17a14024496c3bea3b81362510962785 DNG 5216x3472 5216x3472+0+0 16-bit sRGB 17.4867MiB 0.010u 0:00.003

Command to convert image.out.dpx to image.jpg

Currently, i am using Imagemagick tool of latest version. I encoded a 4K image using this tool and got Image.dsc file as output. Now i decoded this image using a software and got output as "Image.out.dpx". Now i want to convert this decoded (out.dpx) file into jpg format. I want commands to convert this using Imagemagick.
Please anyone help me.
Thanks,
Divya. S
Updated Answer
Please be a little clearer about whether your image is actually of the type I guessed, and also about what actual commands you ran, and if any didn't work, what happened when they failed - including error messages.
Also, please run this command and see if there is any mention of DPX:
identify -list format
...
...
DNG DNG r-- Digital Negative
DOT DOT --- Graphviz
DPX* DPX rw- SMPTE 268M-2003 (DPX 2.0)
Digital Moving Picture Exchange Bitmap, Version 2.0.
See SMPTE 268M-2003 specification at http://www.smtpe.org
DXT1* DDS rw+ Microsoft DirectDraw Surface
DXT5* DDS rw+ Microsoft DirectDraw Surface
...
...
Note the rw- beside DPX in my output, meaning that DPX files can be both read and written.
Original Answer
If your DPX file is this format:
Digital Moving Picture Exchange Bitmap, Version 2.0.
See SMPTE 268M-2003 specification at http://www.smtpe.org
You can convert from that to JPEG with:
magick input.dpx output.jpg
If your ImageMagick is below v7, you will need this instead:
convert input.dpx output.jpg

imagemagick with grayscale not working

I am trying to change a file named "anvil_base.png" to grayscale so I am using imagemagick. What I am entering is convert anvil_base.png -colorspace Gray -gamma 2.2 anvil_base.png
but it is just returning this
Invalid Parameter - -colorspace
What am I doing wrong?
I suspect you are on Windows and you have not put the directory where ImageMagick is installed ahead of other directories in your PATH. You have three choices:
Option 1
As Glenn kindly points out, if you are using ImageMagick version 7 or newer, you can use the new name for convert which is magick, like this:
magick image.png -colorspace gray ...
Option 2
Use the full path to ImageMagick every time, something like this:
C:\ImageMagick-6.9.3\convert ...
Option 3
Change your PATH. So you would need to do:
Start->Programs->Control Panel->System->Advanced
and then choose Environment Variables and change PATH so that it looks like:
PATH=C:\ImageMagick-6.9.3;C:\Windows;C:\Windows\System32
The main thing is that ImageMagick directory is at the start of the PATH. Then Windows will find the convert which is part of ImageMagick before it finds the built-in Windows convert program which converts FAT filesystems to NTFS. If you choose Option 3 above, you need to either log out and back in again, or start a new Command Prompt for the new PATH to become active.

LibVIPS crashing when processing 3.9gb tiff image

I'm currently working on a project where I have an image of around 3.9gb. I want to create a google maps like view for this image (which is something LibVIPS can generate) by executing the following command:
vips-dev-8.1.1\bin\vips.exe dzsave testje-131072.tiff mydz
However when doing this some warnings are shown and after that the program crashes:
vips warning: tiff2vips: no resolution information for TIFF image "testje-131072.tiff" -- defaulting to 1 pixel per mm
vips warning: tiff2vips: no resolution information for TIFF image "testje-131072.tiff" -- defaulting to 1 pixel per mm
vips warning: vips_tracked: out of memory --- size == 48MB
Anyone got a clue what I could do to be able to process an image of this size using Vips? (Or any other library?).
I've done some investigation myself and it seems we need to have BigTiff, I've looked in the VIPS source code and saw the term BigTiff being used a number of times so I suppose it should be supported?
Some information about the image:
Width: 131072
Height: 131072
Chunks: 32x32 (4096x4096 each)
Compression: LZW
When opening the image in a tool like VLIV (Very Large Image Viewer) the image opens fine.
I'm the libvips maintainer. The vips.exe binary includes bigtiff support and should be easily able to process an image of this size. It's challenging to build yourself on Windows, perhaps a week's work, I wouldn't try to make your own unless you are very expert.
I think the problem is probably your input image. I think it is using very large tiles (4096 x 4096). libvips is having to keep two complete lines of tiles in memory, so 4096 x 131072 x 3 x 2 pixels, which is 3GB straight away.
I would remake your source image. Use smaller tiles, perhaps 512 x 512, and make sure you are writing a bigtiff image. Please open an issue on the libvips tracker if you still have problems, it's easier to debug stuff there.
https://github.com/jcupitt/libvips/issues
Edit: there's now an official 64-bit Windows build of libvips and vips.exe, it might help:
http://www.vips.ecs.soton.ac.uk/supported/current/win32/vips-dev-w64-8.1.1-2.zip

Generating a 16-bits per channel PNG file procedurally

Is there any way to generate a 16-bits per channel(RGBA) PNG file using D3DX11SaveTextureToFile?
Or any version of DirectX, any image library(C++), any image format
I tried to use the sample code here:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb205131(v=vs.85).aspx
and modified the function names to D3D11 version.
The program works perfectly when I set the desc.Format to DXGI_FORMAT_R8G8B8A8_UNORM .
But the D3DX11SaveTextureToFile returns E_FAIL when I changed the desc.Format to DXGI_FORMAT_R16G16B16A16_UNORM .
I've tried to use DevIL (developer's image library) but it doesn't support 16-bits per channel png file.
The only format which can save all texture-formats is D3DX11_IFF_DDS. It seems that D3DX11SaveTextureToFile can't save 16Bit pngs. One possibility is to extract the imagedata of your texture and save it manually with one of the possibilities (e.g. OpenCV or libpng) discussed here: Writing 16 bit uncompressed image using OpenCV.

Resources