Convert Dicom Image to JPG - ruby-on-rails

I am trying to convert a dicom file to JPG which I would then use to show as thumbnail for the dicom file. I am using the code below to convert the dicom file but When I execute it I get the following error
'write': no encode delegate for this image format `' # error/constitute.c/WriteImage/1272 (Magick::ImageMagickError)
I am using ruby version 2.7.0 and I have installed ImageMagick 7.1.0-4 and the supportive gems. How to solve this error?
require 'dicom'
require 'rmagick'
include DICOM
dcm = DObject.read("sample.dcm")
image = dcm.image(:frame => 5)
image.normalize.write("test.jpeg");

I had to reinstall ImageMagick-7.1.0-26 along with libgdcm-tools on my system and the above mentioned code worked fine. So Imagemagick needs these additional libraries (libjpeg62-dev, libtiff-dev, libpng-dev, libpng12-0 and libgdcm-tools) to work with these image types. I don't know if this is correct or not but that the problem I was facing has been resolved by following this approach. Here are some of the links which helped me in solving this
Install ImageMagick with JPG TIFF and PNG Delegates
How to configure and build with libgcdm for lossless jpeg conversion
and dicom support

Related

Can we convert a .msg to jpeg using imagemagick?

I need to convert a .msg file to an jpeg image. Can we do it using ImageMagick ?
I tried to run the below command,
magick mail.msg mail.jpeg
but it gives an error :
magick: no decode delegate for this image format `MSG' # error/constitute.c/ReadImage/512.
I need .msg to be converted into an image.
Can you please suggest if that is possible.
Thanks,
Abha

Extract/Convert an (multi-file)image that converted

I have a file made with a program , an image sticker maker .
I know this program saves it's images(probably an image, a bg and a mask) into single file with extension ".adf" .
I couldn't convert the output file with image magick cause of below error :
convert: no decode delegate for this image format `output.adf' # error/constitute.c/ReadImage/532.
I don't know how this Image converted with Image magick .
it's my -list configure result :
Path: [built-in]
Name Value
-------------------------------------------------------------------------------
NAME ImageMagick
Path: configure.xml
Name Value
-------------------------------------------------------------------------------
CC vs10
COPYRIGHT Copyright (C) 1999-2011 ImageMagick Studio LLC
DELEGATES bzlib freetype jpeg jp2 lcms png tiff x11 xml wmf zlib
FEATURES OpenMP
HOST Windows
LIB_VERSION 0x671
LIB_VERSION_NUMBER 6,7,1,0
NAME ImageMagick
RELEASE_DATE 2011-07-15
VERSION 6.7.1
WEBSITE http:// www.image magick.org
I attached the file :
src.adf
* EDIT *
if I run file command on src.adf it tells :
root#MexHex-PC:# file -vv src.adf
file-5.25
magic file from /etc/magic:/usr/share/misc/magic
What's missed !?
Thanks
This src.adf looks like a very minimal & flat data file. I know nothing about Dalahoo3D and/or ArcGis products, but we can quickly extract the embedded images with python.
import struct
with open('src.adf', 'rb') as f:
# Calculate file size.
f.seek(0, 2)
total_bytes = f.tell()
# Rewind to beging.
f.seek(0)
file_cursor = f.tell()
image_cursor = 0
while file_cursor < total_bytes:
# Can for start of JPEG.
if f.read(1) == b"\xFF":
if f.read(3) == b"\xD8\xFF\xE0":
print("JPEG FOUND!")
# Backup and find the size of the image
f.seek(-8, 1)
payload_size = struct.unpack('<I', f.read(4))[0]
# Write image to disk
d_filename = 'image{0}.jpeg'.format(image_cursor)
with open(d_filename, 'wb') as d:
d.write(f.read(payload_size))
image_cursor += 1
else:
f.seek(-3, 1) # Back cursor up, and try again.
file_cursor = f.tell()
Which dumps the following three images...
I'm sure this file was made with Imagemagick. I had already seen that one would convert the file to tiff image. He told me to do this with Imagemagick but did not explain the method.
I'm guessing this is just a matter of miscommunication. It's true that ImageMagick commonly handles JPEG / TIFF formats, but not geographic information systems and/or 3D modeling. That's usually extended by a vendor -- like ArcGIS. I would bet that ImageMagick is present in the workflow of generating TIFF files, but .ADF wouldn't be supported by ImageMagick until someone writes a delegate coder.
Update
From this question, it looks like you'll need to extend ImageMagick delegates to call GDAL utilities. You'll need to update the delegates.xml file to call the correct utility.

get "convert: improper image header" error when convert gif to png using ImageMagick

I am using ImageMagick to convert a gif to multiple png data. But I get this error:
convert: improper image header
/misc/lmbraid11/jingl/webscraping/dataset_2018_05_18/image2018_5_4_10_34.gif'
# error/gif.c/ReadGIFImage/1037. convert: no images defined
/misc/lmbraid11/jingl/webscraping/dataset_2018_05_18/image2018_5_4_10_34.png'
# error/convert.c/ConvertImageCommand/3210.
Here is the command:
convert -coalesce /misc/lmbraid11/jingl/webscraping/dataset_2018_05_18/image2018_5_4_10_34.gif /misc/lmbraid11/jingl/webscraping/dataset_2018_05_18/image2018_5_4_10_34.png
The gif file was downloaded from:
[http://www.niederschlagsradar.de/image.ashx?type=regioloop&regio=fre][1]
ImageMagick version: Version: ImageMagick 6.8.9-9 Q16 x86_64
Any help will be appreciated.
Problem get solved. It turns out that I did not download the gif file correctly, so the gif file was corrupted.
The syntax should be:
convert image2018_5_4_10_34.gif -coalesce image2018_5_4_10_34.png
In your case, you're specifying the option before files, however it can vary on your IM version.
As per #fmw42 comment:
Note that proper ImageMagick syntax reads the input before the -coalesce. Though ImageMagick 6 is forgiving, ImageMagick 7 is not.

Is there a way to read/write XMP metadata using imagemagick?

I would like to read/write XMP metadata in JPEG and PNG files.
I'm able to do this using the exiftool
~ $ exiftool -xmp-dc:description="FooBar" sample.png
1 image files updated
~ $ exiftool sample.png | grep "Description"
Description : FooBar
However, I'm not able to read the XMP Metadata using imagemagick
~ $ identify -verbose sample.png | grep "Description"
My reason to write XMP metadata is that so it can be read by Adobe Products.
Question
Is there a way to read/write XMP metadata using imagemagick?
What you want to ask is "does ImageMagick support reading or writing XMP (descriptive) metadata?". The answer to that question, from reading the documentation, is no. ImageMagick reads (almost) all metadata from a file, but not descriptive metadata.
If for some reason you must use ImageMagick to extract XMP metadata, you could try to include a filter. Filters can be configured to process image files, but they are not part of ImageMagick itself.
convert -ping yourimage.jpg XMP:-
Access XMP data can be done as follows:
ImageMagick.XmpProfile xmp = image.GetXmpProfile();
Console.WriteLine("\n\n----> xmp:" + xmp);
if (xmp != null)
{
you have to process the XML data of the XMPs result.
ie. use XPATH or some other XML interface.
}

convert jpeg/png to tiff in java

I am using batik library for image conversion , I need to convert jpeg/png to tiff format.
Can anyone help me on how to do the conversion using batik (preferable) , because i am using the same library for other SVG conversions.
You could probably do PNG - > SVG - > TIFF conversion.
This link should point you in the right direction:
http://xmlgraphics.apache.org/batik/tools/rasterizer.html
check the "Examples of using the rasterizer task" section.
Hope this helps.

Resources