convert jpeg/png to tiff in java - image-processing

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.

Related

Convert Dicom Image to JPG

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

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

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.

Apply XMP photo manipulation in ImageMagick

I want to automatically manipulate images with ImageMagick (or any other tool that can be run on an Ubuntu server or called via an API). In order to get exactly the result I want, I have tinkered with Photoshop and exported the XMP metadata to document the manipulation. It looks like this:
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.3-c007 1.136881, 2010/06/10-18:11:35 ">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:crs="http://ns.adobe.com/camera-raw-settings/1.0/"
crs:Version="7.0"
crs:ProcessVersion="6.7"
crs:Sharpness="38"
crs:LuminanceSmoothing="0"
crs:VignetteAmount="-17"
crs:VignetteMidpoint="32"
crs:SplitToningShadowHue="0"
crs:SplitToningShadowSaturation="0"
crs:SplitToningHighlightHue="0"
crs:SplitToningHighlightSaturation="0"
crs:SplitToningBalance="-15"
crs:ParametricShadows="-14"
crs:ParametricDarks="-16"
crs:ParametricLights="+4"
crs:ParametricHighlights="+31"
crs:ParametricShadowSplit="25"
crs:ParametricMidtoneSplit="50"
crs:ParametricHighlightSplit="75"
crs:SharpenRadius="+0.5"
crs:SharpenDetail="100"
crs:SharpenEdgeMasking="17"
crs:PostCropVignetteAmount="0"
crs:GrainAmount="24"
crs:GrainSize="2"
crs:GrainFrequency="6"
crs:LensProfileEnable="0"
crs:LensManualDistortionAmount="-2"
crs:PerspectiveVertical="0"
crs:PerspectiveHorizontal="0"
crs:PerspectiveRotate="0.0"
crs:PerspectiveScale="100"
crs:Exposure2012="-0.05"
crs:Contrast2012="0"
crs:Highlights2012="+27"
crs:Shadows2012="+18"
crs:Whites2012="+29"
crs:Blacks2012="+1"
crs:Clarity2012="+6"
crs:ToneCurveName2012="Linear"
crs:LensProfileSetup="Auto"
crs:HasSettings="True">
<crs:ToneCurvePV2012>
<rdf:Seq>
<rdf:li>0, 0</rdf:li>
<rdf:li>255, 255</rdf:li>
</rdf:Seq>
</crs:ToneCurvePV2012>
<crs:ToneCurvePV2012Red>
<rdf:Seq>
<rdf:li>0, 0</rdf:li>
<rdf:li>255, 255</rdf:li>
</rdf:Seq>
</crs:ToneCurvePV2012Red>
<crs:ToneCurvePV2012Green>
<rdf:Seq>
<rdf:li>0, 0</rdf:li>
<rdf:li>255, 255</rdf:li>
</rdf:Seq>
</crs:ToneCurvePV2012Green>
<crs:ToneCurvePV2012Blue>
<rdf:Seq>
<rdf:li>0, 0</rdf:li>
<rdf:li>255, 255</rdf:li>
</rdf:Seq>
</crs:ToneCurvePV2012Blue>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
Now I would like to apply exactly the same manipulation with a tool that can be run server-side. Is it possible ? Can I achieve exactly the same result with ImageMagick ? Does Photoshop expose an API, or maybe a SDK allowing me to do that ?
I think it would be a pretty massive ask of ImageMagick to achieve identical results, or even close, to those achieved by Photoshop.
Adobe puts massive development effort into ACR (Camera Raw) and things like lens profiles require vast amounts of testing and management of databases of lens characteristics on different cameras which are just not part of the remit or objective of ImageMagick.
Also, ImageMagick delegates the RAW processing to UFRAW and I don't believe that supports advanced features like "Clarity" and "Luminance Smoothing".
Photoshop does expose an API which is scriptable - Adobe Photoshop Scripting in JavaScript, AppleScript and VBScript.
One way to accomplish this for RAW photos is to use the free Adobe DNG Converter (available for both Windows and macOS, but the Windows version might run with wine).
When you ask it to convert a RAW to a DNG you can have it embed a full size JPEG preview in the DNG. It will respect whatever settings are in the XMP when generating the JPEG preview. You can ask it to convert a DNG to a second DNG as a way to update the embed preview. And it works from the command line.
Then use something like ExifTool to edit the XMP metadata, and to extract the embed JPEG preview.
I've used this with reasonable success to create a barebones RAW converter:
https://github.com/ncruces/RethinkRAW

using imread of OpenCV failed when the image is Ok

I encountered a problem when I want to read an image using the OpenCV function imread().
The image is Ok and I can show it in the image display software.
But when I use the imdecode() to get the image data, the data returns NULL.
I will upload the image and the code and hope some one could help me
Mat img = imread(image_name);
if(!img.data) return -1;
The image's link is here: http://img3.douban.com/view/photo/raw/public/p2198361185.jpg
PS: The image_name is all right.
I guess OpenCV cannot decode this image. So is there any way to decode this image using OpenCV?, like add new decode library. By the way, I can read this image using other image library such as freeImage.
Your image is in .gif and it is not supported by OpenCV as of now.
Note OpenCV offers support for the image formats Windows bitmap (bmp),
portable image formats (pbm, pgm, ppm) and Sun raster (sr, ras). With
help of plugins (you need to specify to use them if you build yourself
the library, nevertheless in the packages we ship present by default)
you may also load image formats like JPEG (jpeg, jpg, jpe), JPEG 2000
(jp2 - codenamed in the CMake as Jasper), TIFF files (tiff, tif) and
portable network graphics (png). Furthermore, OpenEXR is also a
possibility.
Source - Click here
You can use something like this, to perform the conversion.
I was able to load your image using imread using this. Also, you can check out FreeImage.
You can also try to use the library gif2numpy. It converts a gif image to a numpy image which then can be loaded by OpenCV:
import cv2, gif2numpy
np_images, extensions, image_specs = gif2numpy.convert("yourgifimage.gif")
cv2.imshow("np_image", np_images[0])
cv2.waitKey()
The library can be found here: https://github.com/bunkahle/gif2numpy It is not dependent on PIL or pillow for this like imageio.
There are two methods to read an image in OpenCV, one is using Mat the other one using IplImage. I see you have used the former one. You can try with the second argument of imread also:
image = imread("image.jpg", CV_LOAD_IMAGE_COLOR); // Read the file
else use IplImage
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <opencv2/core/core.hpp>
IplImage* src = 0;
if( (src = cvLoadImage("filename.jpg",1)) == 0 )
{
printf("Cannot load file image %s\n", filename);
}
If they don't work please check if you have installed libjpeg, libtiff and other dependencies for reading an image in OpenCV.
Hope it would help.

Resources