How to read ISO Speed of an image in Octave? - matlab

In MATLAB I used to go:
info = imfinfo('image.jpg');
iso = info.DigitalCamera.ISOSpeedRatings;
And that's it. Octave has an imfinfo function that reads many parameters from the image header, but apparently not the ISO speed. That looks strange to me (why would it read dozens of params and let out ISO speed?).
Is there something I am missing?
Example image is here, shot with a DSLR (as you can see with imfinfo). With MATLAB, I can clearly see that imfinfo('image.jpg').DigitalCamera.ISOSpeedRatings is 200.

tl;dr
The value you want is under the field PhotographicSensitivity. Use:
iso = imfinfo ("image.jpg").DigitalCamera.PhotographicSensitivity;
See Octave bug #47706.
Octave only considers tags that follow Exif version 2.3.
Workaround
Old versions of the Octave image package had a function readexif (the function was deprecated in image package version 2.2.0 and removed in version 2.4.0) which may be able to read them. The last version to include that function was 2.2.2
Discussion
The details you are accessing are the EXIF values on your image file. Basically, there's a table on your file that maps tags, such as ExposureTime or FNumber, to their actual values. However, the tag names are not encoded in the file. Instead, each tag has an integer value e.g., ExposureTime or FNumber will appear as 33437 and 33434 respectively. It's the job of a program/library to map those integer values to the tag name.
The tag you are looking for, ISOSpeedRatings is not a valid EXIF tag per the EXIF specs version 2.3 (the latest specs, released in 2010). It was renamed to PhotographicSensitivity. If you read the specs under that tag, you will find this note:
Note that this tag was referred to as “ISOSpeedRatings” in versions of this standard up to Version 2.21.
If you read even more of the specs, you will find the following explanation on Annex G:
[...] the PhotographicSensitivity tag whose ID was 34855 was previously referred to as ISOSpeedRating, which, in reality, led to confused interpretations of sensitivity that resulted in many recordings that differed from ISO speed as defined under the ISO 12232 standard.
And if you read even more of the specs, you will notice that the meaning of the value with the tag 34855 was slightly changed when its name changed. This means that it's not only a tag name issue, its meaning is different if your camera follows a different version of the EXIF specs (assuming that your camera recorded it correctly, remember that the reason for the change was that cameras were recording the wrong thing).
I'm not sure what is the right technical answer. I'm guessing a program should check the recorded ExifVersion (which is the EXIF tag 36864) and change the tag names according to that.
Edit
Octave uses GraphicsMagick to read images, including its metadata. GraphicsMagick does not accept the EXIF tag numbers, programs need to query using the tag names. Octave then has a hardcoded list of tag names but only includes the tags for Exif specs 2.3. It seems that GraphicsMagick recognizes your file is an older version of Exif and names the tag old way which Octave does not ask for.

I did the following and can now use readexif from 2.2.2 in image 2.6.1:
Download Image 2.2.2 as suggested earlier in this thread
Add the readexif.m from Image 2.2.2 among image 2.6.1
Reload package pkg load image
Now you can call readexif. To get ISOSpeedRating:
readexif(JPGPath).Exif_IFD_Pointer.ISOSpeedRatings

Related

keep/copy XMP with libexif

I try to add a thumbnail to a JPEG picture using libexif.
For now I'm borrowing the code from exif (the command line tool that is shipped by the libexif team).
However I noticed the XMP tags get deleted from the metadata. There is an old bugreport here.
I tried to see how to achieve this anyway with libexif but I don't really understand how to get the XMP from input file and put it in the output file. I just want to copy all XMP data, I don't need to extract anything of it.
I saw there is a TAG EXIF_TAG_XML_PACKET in exif_tag.h but couldn't figure out how to read/write this tag.
A related solution is in this SO answer but it looks complicated. I'm not familiar coding in C.
Is it actually possible to keep all XMP when using only libexif API? Have things changed in recent years on that? How would you write this in code?
Thanks
I believe it should be somewhat straightforward. XMP fields are described in the ISO/Adobe standard. Regular Kotlin/Java/Android file I/O and some string manipulation should be all that is required.
I would start out by becoming intimately familiar with ISO 16684-1:2019. Then, write a method for your jpeg file class that grabs all the XMP fields. Store those fields in a temp file (to prevent difficult to recover data loss in the event of your code or libexif crashing). Hand the file off to libexif. Generate the thumbnail. Finally, when that's done you can restore the XMP fields. If the thumbnail is stored in an XMP field as well (and it sounds like it is), it may be easier to concatenate that field with the other ones which were already grabbed, updating the temp file so that it contains EVERY XMP field, before adding all of the XMP fields back to the jpeg.
Unfortunately, I do not currently have the time to read a 50 page ISO standard, synthesize the information, and then write the code to implement the solution. Here's a link to the standard at least, to get you started.
https://www.iso.org/obp/ui/#iso:std:iso:16684:-1:ed-2:v1:en

Kodi (fka Xbmc) scraper for onlinetvrecorder (otr) recordings

I would like scrape information for recordings from onlinetvrecorder (otr) in Kodi. Unfortunately the scrapers available can't handle the file format which is like
Django_Unchained_15.07.03_22-45_sf2_165_TVOON_DE.mpg.mp4.avi
Renaming is not an option, since the filename is a key for otr. I know there is a scraper called xbmc-otr, but it never left beta status and seems to be outdated.
Any suggestions, on how to correctly display those files in Kodi?
Has anybody written or started a scraper for otr?
After some research I found a solution to the problem. Put the following in %appdata%\Kodi\userdata\advancedsettings.xml (advancedsettings.xml does not exist in advance, you have to create it)
<advancedsettings>
<video>
<cleanstrings action="prepend">
<regexp>_\d\d\.[0-1]\d\.[0-3]\d_[0-2]\d-[0-5]\d_</regexp>
</cleanstrings>
</video>
</advancedsettings>
The regexp <regexp>_\d\d\.[0-1]\d\.[0-3]\d_[0-2]\d-[0-5]\d_</regexp> matches the timestamp in the otr filename, so that everything right of the match (at the end of the file name) is removed. See the official Kodi documentation for further reference. The remaining file name can be handled by the scrapers shipped with Kodi.
Despite of the relatively coarse regexp I added, all my otr movies were recognized correctly.
The solution is tested with Kodi 15.2 (Isengard), but should work with all versions that support the cleanstrings option.
EDIT:
A similar soltuion works for TV Shows. The only requirement is that the file name contains season and episode information like S01E02 for example.
<tvshowmatching action="prepend">
<regexp>_[Ss]([0-9]+)[Ee]([0-9]+)([^\\/_]*)</regexp>
</tvshowmatching>

Multi-bitrate encoding with ffmpeg

How can I generate multiple versions of the same video file at different bitrates that are properly key-frame aligned? Is it posible with ffmpeg?
Here is an article with example http://www.wowza.com/forums/content.php?192-Encoding-Suggestions-for-Video-on-Demand
The article says that "Multi-birate encoding has not worked using ffmpeg". Is it right?
use two-pass encoding, process first pass with the lowest resolution and then encode again each resolution with pass=2 which will use stats generated with first pass. this will guarantee keyframes to be in excactly the same places.
You should use no-scenecut, keyint and min-keyint options. Set the keyint and min-keyint options to the same values.
For example:
keyint=70:min-keyint=70:no-scenecut

How to use PDFTextExtractor on iTextSharp

I want to retrieve the text from a pdf file using iTextSharp. However, I wasn't able to use PDFTextExtractor as in JAVA library of itextsharp(itext). I need readPDFOffline class to return content of file. I will give the pseudo below for you to understand well what I want.
private string readPDFOffline(string fileUri);
read PDF;
retrieve Text Content of This Pdf;*
save content into string contentOfflineFile;
return contentOfflineFile;
I would like to do the * part of Code
PdfTextExtractor is present in the most recent releases of iTextSharp, available here.
Retrieving text in PDF is not easy. Not impossible, but there are times when the only thing that will work is OCR. For all other cases, PdfTextExtractor should work. Cases of it not working are considered bugs and should be reported as such.
Be aware that there are several cases where what looks like valid text is not extractable:
Text with no encoding... just glyph indexes. OCR time.
"Text" that is just raw paths. Horribly inefficient, and time for more OCR.
"Text" that is pixels in a bitmap. OCR once more.
OCR: Optical Character Recognition. There's even a reasonably good one for free available on Google Code, though I don't recall the name off the top of my head.

How do I use IPTC/EXIF metadata to categorise photos?

Many photo viewing and editing applications allow you to examine and change EXIF and IPTC data in JPEG and other image files. For example, I can see things like shutter speed, aperture and orientation in the picture files that come off my Canon A430. There are many, many name/value pairs in all this metadata. But...
What do I do if I want to store some data that doesn't have a build-in field name. Let's say I'm photographing an athletics competition and I want to tag every photo with the competitor's bib number. Can I create a "bib_number" field and assign it a values of "0001", "5478", "8124" etc, and then search for all photos with bib_number="5478"?
I've spent a few hours searching and the best I can come up with is to put this custom information in the "keywords" field but this isn't quite what I'm after. With this socution I'd have to craft a query like "keywords contains bib_number_5478" whereas what I want it "bib_number is 5478".
So do the EXIF and/or IPTC standards allow addtional user-defined field names?
Thanks
Kev
It can be used for that, but it really shouldn't: it's meant to be user-editable and so isn't a safe place to put critical metadata. Using an XMP sidecar is better for this kind of thing: in XMP, any field added that a given app does not understand is, according to the standard, supposed to be ignored by that app and not destroyed.
I don't know if there are applications to do this but by the standards described for JPEG files there is a field called Comments where you can assign values that could act like tags.
C# code:
using System.Windows.Media.Imaging;
using System.IO;
...
FileStream fs = new FileStream(#"<img_path>", FileMode.Open, FileAccess.ReadWrite);
BitmapMetadata bmd = (BitmapMetadata)BitmapFrame.Create(fs).Metadata;
bmd.Comment = "Some Comment Here";
also if you are looking for an application that already has this functionality built into it, then might i recommend Irfan View (open pic, go to Image menu, click on Comments button).
Hope this helps.