How can I export .hdr or .exr image from iPhone HDRI photo (.HEIC format)? - iphone

I want to take HDR photos with my iPhone and get images as .hdr or .exr image formats, in order to use them for my cinema rendering purpose.
I took some HDR photos with my iPhone X and sent them to my iMac, and then I tried converting them from .HEIC format to .exr format with sips command like below:
sips -s format exr image.HEIC
However, it turned out that output .exr images seemed not to be adequate OpenEXR images. Actually I tried to import one of the images with OpenCV in Python and checked its max RGB value on numpy ndarray like below, but it was just 1.0, although there was obviously very bright light there.
img = np.array(cv.imread(img_path, cv.IMREAD_ANYCOLOR | cv.IMREAD_ANYDEPTH))
print(img.max())
How can I get HDR images in the right way with my iPhone? If you know any other better ways to do that, can you tell me about it? Thank you.

Related

How do I use imagemagick to convert HEIC to JPG and preserve quality?

I'd like to batch convert .heic images (e.g. iPhone photograph) to .jpg files with imagemagick, with the goal of retaining as much of the quality from the original image as possible. To be clear, the resulting output size is not a concern.
I've been using
magick input.heic -quality 100% output.jpg
Is it possible to do better?
No, its not possible to do better per ImageMagick's website:
Set the quality to 100 to produce lossless HEIC images. Requires the libheif delegate library.
I interpret lossless as NOTHING is lost from original picture. However since you ARE converting to another file type maybe its possible you lose something, are you seeing any artifacts/issues?

Artifacts appear using imread function from opencv

I use imread function to read one jpeg file and save the rgb image in bmp format. Comparing the two files, I found artifacts appear and use green circle to denote artifacts. The version of OpenCV is 3.0. I compile the libraries by myself with SSE, SSE2 and SSE3 switchd on (default setting). My OS is windows 7 professional. You can use the following image to check.
original jpeg image
saved bmp file
If I read the jpeg file in Matlab, the rgb image is correct. I save rgb image in png format in Matlab, read the png file using opencv and save the loaded image in bmp file. Everything is OK. It seems that there is a problem with jpeg decoder. The jpeg library used is libjpeg.lib.
Due to the size limit, I cut the patch from the second image.
You're always going to get some artifacts in JPEG. You can reduce the appearance of such artifacts by changing the quantization tables used (usually with loss of compression).
JPEG encoders often use a "quality" setting to change the quantization tables.

PIL: converting an image with mode "I" to "RGB" results in a fully white image

The image at the end of this question is a PNG with mode I, which stands for Indexed, as far as I can tell.
I'm trying to create a thumbnail out of it, and save it as JPG with PIL.
However, is I leave the mode alone, PIL won't let me resize it with error unable to generate thumbnail: cannot write mode I as JPEG.
If I convert it to RGB, the result will be a fully white image.
Is there a way to fix this?
https://www.dropbox.com/s/2d1edk2iu4ixk25/NGC281.png
The input image is a 16-bit grayscale PNG, and it appears PIL has a problem with this. Manually converting it to an 8-bit image before further processing makes it work again.
The problem may originate inside PIL itself. The PyPNG homepage asserts
..PIL only has internal representations (PIL mode) for 1-bit and 8-bit channel values. This makes me wonder if PIL can read PNG files with bit depth 2 or 4 (greyscale or palette), and also bit depth 16 (which PNG supports for greyscale and RGB images).
Then again, that page is from 2009. It could be worth tracking down where PIL is maintained from, and report this as a bug (? Or possibly a feature request?).

Tesseract Trained data

Am trying to extract data from reciepts and bills using Tessaract , am using tesseract 3.02 version .
am using only english data , Still the output accuracy is about 60%.
Is there any trained data available which i just replace in tessdata folder
This is the image nicky provided as a "typical example file":
Looking at it I'd clearly say: "Forget it, nicky! You cannot train Tesseract to recognize 100% of text from this type of image!"
However, you could train yourself to make better photos with your iPhone 3GS (that's the device which was used for the example pictures) from such type of receipts. Here are a few tips:
Don't use a dark background. Use white instead.
Don't let the receipt paper crumble. Straighten it out.
Don't place the receipt loosely on an uneven underground. Fix it to a flat surface:
Either place it on a white sheet of paper and put a glas platen over it.
Or use some glue and glue it flat on a white sheet of paper without any bend-up edges or corners.
Don't use a low resolution like just 640x480 pixels (as the example picture has). Use a higher one, such as 1280x960 pixels instead.
Don't use standard exposure. Set the camera to use extremely high contrast. You want the letters to be black and the white background to be really white (you don't need the grays in the picture...)
Try to make it so that any character of a 10-12 pt font uses about 24-30 pixels in height (that is, make the image to be about 300 dpi for 100% zoom).
That said, something like the following ImageMagick command will probably increase Tesseract's recognition rate by some degree:
convert \
http://i.stack.imgur.com/q3Ad4.jpg \
-colorspace gray \
-rotate 90 \
-crop 260x540+110+75 +repage \
-scale 166% \
-normalize \
-colors 32 \
out1.png
It produces the following output:
You could even add something like -threshold 30% as the last commandline option to above command to get this:
(You should play a bit with some variations to the 30% value to tweak the result... I don't have the time for this.)
Taking accurate info from a receipt is not impossible with tesseract. You will need to add image filters and some other tools such as OpenCV, NumPy ImageMagick alongside Tesseract. There was a presentation at PyCon 2013 by Franck Chastagnol where he describes how his company did it.
Here is the link:
http://pyvideo.org/video/1702/building-an-image-processing-pipeline-with-python
You can get a much cleaner post-processed image before using Tesseract to OCR the text. Try using the Background Surface Thresholding (BST) technique rather than other simple thresholding methods. You can find a white paper on the subject here.
There is an implementation of BST for OpenCV that works pretty well https://stackoverflow.com/a/22127181/3475075
i needed exactly the same thing and i tried some image optimisations to improve the output
you can find my experiment with tessaract here
https://github.com/aryansbtloe/ExperimentWithTesseract

How to change background color of an eps file while converting it to jpeg or png

I am converting eps (Encapsulated PostScript) files to jpeg files with ghostscript. A sample command I use is:
gswin32.exe -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r600x600 -dGraphicsAlphaBits=4 -dUseCIEColor -dEPSCrop -sOutputFile=”a.jpeg” b.eps
The input eps files come with white backgrounds (I only have their clipping path). What I need to do is change this white background to another color in the output images, or it would be even better if I could make them transparent (output file format would be png). How can I do this?
never tried it myself but you should be able to convert your eps file into png by setting:
-sDEVICE=pngalpha
also the pngalpha device has a -dBackgroundColor option:
-dBackgroundColor=16#RRGGBB (RGB color, default white = 16#ffffff) For
the pngalpha device only, set the
suggested background color in the PNG
bKGD chunk. When a program reading a
PNG file does not support alpha
transparency, the PNG library converts
the image using either a background
color if supplied by the program or
the bKGD chunk. One common web browser
has this problem, so when using on a web page you
would need to use
-dBackgroundColor=16#CCCC00 when creating alpha transparent PNG images
for use on the page.
more details here: Details of Ghostscript output devices see section 3.1. PNG file format
After you've obtained your (white background) images from Ghostscript, you could use ImageMagick's convert or GraphicMagick's gm convert commands to change the white to transparent background:
convert -background transparent my.png my_transp.png