exiftool returns Unknown (1 0) as Extra Samples values for an tif image - transparency

I am using exiftool to find out if an tif image has any alpha property(to check transparency).
The command I am using is like
exiftool -ExtraSamples -T abcd.tif
From this link I understood the concept of checking alpha
I have normally seen exiftool return 'Associated Alpha' or 'Unassociated Alpha' as Extra Samples value
But for one particular file Extra Samples value returns 'Unknown (1 0)'
Can anyone please explain what does this mean?

Related

Check in which Image in a dataset I get the warning libpng warning: iCCP: known incorrect sRGB profile while using OpenCV

I have a dataset, it has 2500 images. To access each of them and apply normalization, I loop over the images:
for path_to_image in dataset:
image = cv2.imread(path_to_image)
# rest of the code follows
While running the code I get this error/warning libpng warning: iCCP: known incorrect sRGB profile while using OpenCV
I tried to use some tricks to get the approximate value of iteration where the image is not being read properly but it did not work.
Is there any way I can obtain the variable path_to_image where I get this error?
What I was thinking is there must be a variable that stores some information about the warning.
Would be grateful for any help.

How to use mogrify (ImageMagick) to convert from NEF to *.jpg and retain EXIF data?

I'm converting about 9000 photos from .NEF to .jpg.
I'd like to retain all EXIF data, most importantly Date and time created, Latidude and Longitude.
I'd like the JPGs to be at the highest possible quality.
I've just gotten started using ImageMagick from the command line. I also have Exiftool installed. I'm using the mogrify command because it handles batches nicely.
When I run
mogrify -format jpg *.NEF
All of my .NEF files are successfully converted to JPGs, but all EXIF data are lost.
I've searched around quite a bit to try and find a solution to this and it seems like I may have to install ufraw, but if possible I'd like a solution that uses software I already have - ImageMagick and Exiftool.
Thanks in advance for any advice you have about how to do this.
Update:
The images I converted using mogrify are slightly smaller (~ 1-2 MB) than those output by my colleague using picasa to convert NEF to JPG. But when I specify -quality 100 in ImageMagick the image sizes gain about 45 MB! Why?
The code exiftool -tagsfromfile %d%f.NEF -ext jpg -overwrite_original . adds the exif information to the JPGs.
Think twice before doing this - you really are discarding a lot of information - and if you don't want it, why not shoot JPEG instead of RAW in the first place?
FWIW, you can use ImageMagick to get the JPEG:
convert somefile.NEF somefile.jpg
Then you can copy the tags across from the original to the file newly created by ImageMagick:
exiftool -tagsfromfile somefile.NEF -all:all somefile.jpg
If you have thousands of images, and are on macOS or a decent Linux/Unix-based OS, I would recommend GNU Parallel like this and it will keep busy all those lovely cores that you paid Intel so dearly for:
parallel --dry-run 'convert {} {.}.jpg; exiftool -tagsfromfile {} -all:all {.}.jpg' ::: *nef
Sample Output
convert a.nef a.jpg; exiftool -tagsfromfile a.nef -all:all a.jpg
convert b.nef b.jpg; exiftool -tagsfromfile b.nef -all:all b.jpg
and if that looks good remove the --dry-run so it actually runs the command.
If you are on Windows, you will have to do some ad-hoc jiggery-pokery to get it done in any reasonable time frame. You can use the mogrify command and get all the conversions done to JPEG and then do all the exiftool re-embedding of the EXIF data later. If your files are named with some sort of system with incrementing numbers, you can start two or three copies of mogrify in parallel - say one doing files whose names end in [0-4] and another one doing files whose names end in [5-9]. I don't speak Windows, but that would probably look like these two commands each running in its own Command Prompt:
mogrify -format jpg *0.NEF *1.NEF *2.NEF *3.NEF *4.NEF
mogrify -format jpg *5.NEF *6.NEF *7.NEF *8.NEF *9.NEF
Then you would do the exiftool stuff when they had all finished but you would have to use a FOR loop like this:
FOR %%G IN (*.NEF) DO (
exiftool -tagsfromfile %%G -all:all %%~dpnG.jpg
)
The %%~dpnG part is a guess based on this answer.

A guide to convert_imageset.cpp

I am relatively new to machine learning/python/ubuntu.
I have a set of images in .jpg format where half contain a feature I want caffe to learn and half don't. I'm having trouble in finding a way to convert them to the required lmdb format.
I have the necessary text input files.
My question is can anyone provide a step by step guide on how to use convert_imageset.cpp in the ubuntu terminal?
Thanks
A quick guide to Caffe's convert_imageset
Build
First thing you must do is build caffe and caffe's tools (convert_imageset is one of these tools).
After installing caffe and makeing it make sure you ran make tools as well.
Verify that a binary file convert_imageset is created in $CAFFE_ROOT/build/tools.
Prepare your data
Images: put all images in a folder (I'll call it here /path/to/jpegs/).
Labels: create a text file (e.g., /path/to/labels/train.txt) with a line per input image . For example:
img_0000.jpeg 1
img_0001.jpeg 0
img_0002.jpeg 0
In this example the first image is labeled 1 while the other two are labeled 0.
Convert the dataset
Run the binary in shell
~$ GLOG_logtostderr=1 $CAFFE_ROOT/build/tools/convert_imageset \
--resize_height=200 --resize_width=200 --shuffle \
/path/to/jpegs/ \
/path/to/labels/train.txt \
/path/to/lmdb/train_lmdb
Command line explained:
GLOG_logtostderr flag is set to 1 before calling convert_imageset indicates the logging mechanism to redirect log messages to stderr.
--resize_height and --resize_width resize all input images to same size 200x200.
--shuffle randomly change the order of images and does not preserve the order in the /path/to/labels/train.txt file.
Following are the path to the images folder, the labels text file and the output name. Note that the output name should not exist prior to calling convert_imageset otherwise you'll get a scary error message.
Other flags that might be useful:
--backend - allows you to choose between an lmdb dataset or levelDB.
--gray - convert all images to gray scale.
--encoded and --encoded_type - keep image data in encoded (jpg/png) compressed form in the database.
--help - shows some help, see all relevant flags under Flags from tools/convert_imageset.cpp
You can check out $CAFFE_ROOT/examples/imagenet/convert_imagenet.sh
for an example how to use convert_imageset.

ImageMagick to verify image integrity

I'm using ImageMagick (with Wand in Python) to convert images and to get thumbnails from them. However, I noticed that I need to verify whether a file is an image or not ahead of time. Should I do this with Identify?
So I would assume checking the integrity of a file needs the whole file to be read into memory. Is it better to try and convert the file and if there was an error, then we know the file wasn't good.
seems like you answered your own question
$ ls -l *.png
-rw-r--r-- 1 jsp jsp 526254 Jul 20 12:10 image.png
-rw-r--r-- 1 jsp jsp 10000 Jul 20 12:12 image_with_error.png
$ identify image.png &> /dev/null; echo $?
0
$ identify image_with_error.png &> /dev/null; echo $?
0
$ convert image.png /dev/null &> /dev/null ; echo $?
0
$ convert image_with_error.png /dev/null &> /dev/null ; echo $?
1
if you specify the regard-warnings flag with the imagemagick identify tool
magick identify -regard-warnings myimage.jpg
it will throw an error if there are any warnings about the file. This is good for checking images, and seems to be a lot faster than using verbose.
I the case you use Python you can consider also the Pillow module.
In my experiments, I have used both the Pyhton Pillow module (PIL) and the Imagemagick wrapper Wand (for psd, xcf formats) in order to detect broken images, the original answer with code snippets is here.
Update:
I also implemented this solution in my Python script here on GitHub.
I also verified that damaged files (jpg) frequently are not 'broken' images i.e, a damaged picture file sometimes remains a legit picture file, the original image is lost or altered but you are still able to load it.
End Update
I quote the full answer for completeness:
You can use Python Pillow(PIL) module, with most image formats, to check if a file is a valid and intact image file.
In the case you aim at detecting also broken images, #Nadia Alramli correctly suggests the im.verify() method, but this does not detect all the possible image defects, e.g., im.verify does not detect truncated images (that most viewers often load with a greyed area).
Pillow is able to detect these type of defects too, but you have to apply image manipulation or image decode/recode in or to trigger the check. Finally I suggest to use this code:
try:
im = Image.load(filename)
im.verify() #I perform also verify, don't know if he sees other types o defects
im.close() #reload is necessary in my case
im = Image.load(filename)
im.transpose(PIL.Image.FLIP_LEFT_RIGHT)
im.close()
except:
#manage excetions here
In case of image defects this code will raise an exception.
Please consider that im.verify is about 100 times faster than performing the image manipulation (and I think that flip is one of the cheaper transformations).
With this code you are going to verify a set of images at about 10 MBytes/sec (using single thread of a modern 2.5Ghz x86_64 CPU).
For the other formats psd,xcf,.. you can use Imagemagick wrapper Wand, the code is as follows:
im = wand.image.Image(filename=filename)
temp = im.flip;
im.close()
But, from my experiments Wand does not detect truncated images, I think it loads lacking parts as greyed area without prompting.
I red that Imagemagick has an external command identify that could make the job, but I have not found a way to invoke that function programmatically and I have not tested this route.
I suggest to always perform a preliminary check, check the filesize to not be zero (or very small), is a very cheap idea:
statfile = os.stat(filename)
filesize = statfile.st_size
if filesize == 0:
#manage here the 'faulty image' case
Here's another solution using identify, but without convert:
identify -verbose *.png 2>&1 | grep "corrupt image"
identify: corrupt image 'image_with_error.png' # error/png.c/ReadPNGImage/4051.
i use identify:
$ identify image.tif
00000005.tif TIFF 4741x6981 4741x6981+0+0 8-bit DirectClass 4.471MB 0.000u 0:00.010
$ echo $?

Using Delphi or FFMpeg to create a movie from image sequence

My Delphi app has created a squence called frame_001.png to frame_100.png.
I need that to be compiled into a movie clip. I think perhaps the easiest is to call ffmpeg from the command line, according to their documentation:
For creating a video from many images:
ffmpeg -f image2 -i foo-%03d.jpeg -r 12 -s WxH foo.avi
The syntax foo-%03d.jpeg specifies to use a decimal number composed of three digits padded with zeroes to express the sequence number. It is the same syntax supported by the C printf function, but only formats accepting a normal integer are suitable.
From: http://ffmpeg.org/ffmpeg-doc.html#SEC5
However my files are (lossless) png format, so I have to convert using imagemagick first.
My command line is now:
ffmpeg.exe -f image2 -i c:\temp\wentelreader\frame_%05d.jpg -r 12 foo.avi
But then I get the error:
[image2 # 0x133a7d0]Could not find codec parameters (Video: mjpeg)
c:\temp\wentelreader\Frame_C:\VID2EVA\Tools\Mencoder\wentel.bat5d.jpg: could not
find codec parameters
What am I doing wrong?
Alternatively can this be done easily with Delphi?
Not sure if you are interested but there are delphi headers for this # http://ultrastardx.svn.sourceforge.net/viewvc/ultrastardx/trunk/src/lib/ffmpeg/
So you can use the DLL vs command line.
-Brad
Look at the file name in the error message. That can't possibly be right. The percent sign needs to get all the way to the program you're running, but it's being expanded by the batch file instead, where %0 expands to the full name and path of the file. Double the percent sign in the batch file:
ffmpeg.exe -f image2 -i c:\temp\wentelreader\frame_%%05d.jpg -r 12 foo.avi
Also, why do you want five digits when you've already said your files are named like frame_001.png, which has only three digits?
ffmpeg can create a movie from png images, why do you think you have to convert them to jpeg?
Guys in DelphiFFMpeg have been produced a component wrapper for FFMpeg. It's very expensive but it's worth to test it. However what you want to do is very simple and command-line is more than enough for you.

Resources