gtatters / Thermimage

R Package for working with radiometric thermal image files and data
GNU General Public License v3.0
165 stars 41 forks source link

convertflirJPG() seems to think flir jpg files are empty #18

Closed Jonathan-Gore closed 3 years ago

Jonathan-Gore commented 3 years ago

When using the convertflirJPG() function the exiftool command prompt call seems to think that the FLIR.jpg files are empty, even though they are not and CAN be imported into R with the readflirJPG() command.

The resulting error message from exiftool is: "Error: File is empty - -"

My call of the convertflirJPG():

convertflirJPG(C:/git/IR_60901.jpg, exiftoolpath="installed", res.in="640x480", endian="lsb", outputfolder=, verbose=TRUE)

Any thoughts? Much appreciated!

(Image being referenced attached) IR_60901

gtatters commented 3 years ago

I think your res settings are not appropriate for the underlying thermal data embedded inside that jpg. try:

metadata<-flirsettings("C:/git/IR_60901.jpg") metadata$Info$RawThermalImageHeight 348 metadata$Info$RawThermalImageWidth 464

convertflirJPG("C:/git/IR_60901.jpg", exiftoolpath="installed", res.in="464x348", endian="lsb", verbose=TRUE)

image

gtatters commented 3 years ago

But I think you should set endian="msb" for this image. It will create a washed out greyscale but the underlying image won't be corrupted. You can just adjust brightness and contrast in ImageJ or photoshop.

image

image-2

Jonathan-Gore commented 3 years ago

Thanks!

For some reason I thought your function would upscale the base thermal image, although now thinking about it that wouldn't really make a lot of sense.

When I translate the function call you gave above

convertflirJPG("C:/git/IR_60901.jpg", exiftoolpath="installed", res.in="464x348", endian="lsb", verbose=TRUE)

into it's twin CMD call

"exiftool" "C:/git/ThermalAspen/IR_60901.jpg" -b -RawThermalImage | convert - gray:- | convert -depth 16 -endian msb -size 464x348 gray:- "C:/git/ThermalAspen/output/IR_60901.png"

I successfully get the same outputs as you posted! But if I use the same settings for a convertflirJPG() function call I get a whole mess of text with the main warning message:

Warning message: In system2(exiftool, args = exifvalsrawunix, stdout = TRUE) : running command '"exiftool" "C:/git/IR_60901.jpg" -b -RawThermalImage | convert - gray:- | convert -depth 16 -endian msb -size 464x348 gray:- "C:/git/output/IR_60901.png"' had status 99

I'm struggling to find any references to what status 99 could be referring to in regards to a system2() call. Do you have any ideas?

This has been immensely helpful!

Here is the giant wall of text I get when trying to run that convertflirjpg() from R, due its convolution it is hard to properly format it with markdown.

îÇœ.†æD|ŒJžV[ù•;dþíË»w2š¸œ.Ùø•ççi–»ÿK1?+} Ý^p/eìó”#áÌ­&[ù ÖC(Ž [1] "Error: File is empty - -"
[2] "‰PNG"
[3] "\032"
[4] ""
[5] "\b/ˆ\a$¤\bñ\020xC‘ \u0081'\036BB\022ì\020ÇÄ¡\u009dn÷\Ý]ó­ºuçáðý¬ïùÝ}nµ×ÑÙÃ\032~óú­qソ÷—\017»Ãn\vûÜ\u009dÝ\u009dY¿ýîÌ~Ÿ$q»ÝÓu%§¸Æ\036v\u008f’t&wgögR.%Ö\u009dôBul~qb\017¹"
[6] "zLmڙݽåýa÷ùá¥ý£Ý“ÝÅä(^%ž®ÜC%\004Pž\017[\031y/íî¯\ržI^Ô\u009dÙ]ß½µ_Lꓤ C9T·üÓ\\\u009dß]Èÿ…Ý­Ýíäxœÿ“\034\037åÿxww÷0Ç'‰SÖïLîJí¹Ü}vxmÿçv¿\026l\017“ÒPù\u0081¿Ñ<\024\u009d\017·çò;“?ù}¶ûQ°ž\rî\037æwow9p†Rg°" [7] "Éq0lR.%[Ž\rç\027%†ûçÃp$vr\027²£?}\rD¥'ŽüªýrH:•\020ëØ'íÜ’éùȵÖU(¥ài8¾\023./„××sþIÊž\u008d”‹m œ]\030ÀG9\rø\u008f]\u0090Ey/>¹Ð\024\vÝ}}÷~ ï\002±4—\a’\034-Ž\035$SB¹u¬–ª\037–x7q¥kh›¼•„Ò\033\025•\tºÏE“ôˆf:{¼dÂn.î>9ìw7ö¯E\002\037>ã¡Z\006íL\005º\021U\023\u0090Tó{ž€Š£Ä¸~\032à \024ÌI|Hiù\u0081äÜP\006FH­\032×öçwWCÞ½00\024͹¢(ž²\017ÎóP6j©@Þ{a](ý®ö1€G‰" [8] "s÷J„¥|¹‘¶\005•ìñ2§\u008fc6TØ¿Ü\u008fR­)yÌ\002ž3‰ï™\"v»ßÞ¿µ»™Ø©žå¢ÆSùÀÕ\022\024Hyª(³=ì>Ú½\033\t\\\016†‹»7v/çŠ9,\a¸Î›L@)w½zþ¸aj®Jat2|£j~¹\026\034›ÖóŠÌ¡P[ºv2×ÎR\a\032­V³uNÊŽS;¥Bꓘ=Ý(}&ŽéAdwoá¯Ô"
[9] "\001|%'Œ$\032ã®\024”ÊVLi\u008fV\031:+u宜¶¬r½\037ø­ìÜ"
[10] "\u008d¶Ä!:âŠ[ÅÅn˜'\u008f³j\f⤢ìqx:Ÿ²ýÁEóm\b4"
[11] "±îöií„LJ'9–9GùKܨe ¸Ÿk%[ªqÊ)õ`wu\u008fì–m‰âÙJºŸ;\006-ô¸.sÐ:Ë¡ŠNû\"­q¯¥e}oyñG\"S\026ž\032ŠÈá\Z±—R5Ò\032¦B\016ugcB÷¢îñÛ ¶t!\023ú.b¿¶{g÷bx)\037M\003y»ê\u009düTt3"
[12] "Ú/å"
[13] "’ûGñ£·ƒ÷rÚïGiíÏïþhw#Š¥²Bø¢\034AkhJiªT
É^“Ò©ÙLî\r\036É•NGØ&LÙ“Ҙ¦£¬ÿ3á…«\021š«GxU\021¿±˜‘º\034ç#Ù‡)÷yÒ¹¶W\003ç~îA…i €;¦{JÁä‘.°%º ƒ§\u0081þQ®..9ƒÔ00[\031Pˆç\u008dï3)‰“Ò»‹öÏï>\rœ­úUÿ )UZ\v¥´U²Åx\b?\002h\017r¼\021;¹\033\rk(¾¶ÿÚî—vß\u008dÎ\037,ºÑ\017vËŸ\003¬\002\037â‡Ý\001½2ì\016‰®‚CL\v­{fy¼]\031åÙîËpÅ\A«VE]Æ"
[14] "Ý‘rŠ£ÂÛð?\017‘(ä\003©êRzÊlÌ•ÉÒR"
[15] ".F$‡¨Š'\033nš\037n\020ä;›nÖµˆðvTZ\025ãýä?ut‡Çª¥|àôRLìâîJr1Ôº‡á¢çÒ­DÛNj¿\024¸îÏGewv?ÛýaŽoì¾\032\032^\fE\037Äxu\036ýÊËH/‰Ç0\022mŠc¥Q‰–+e+Gpà+E½kª\034r7l)-ù¼\026ƒ\r£’OõÒÚ¯©J…WómÛ@o8–Ó‘Œõ\"\036F\022îuûî%O­¡¹ÎÆÀ/'ÿàƒ\u009dî‡î\ž„Vþ:p-óåT-úج\005\005ÃÕœ‹\021˜J`\037-"
[16] "ÍÛöóÑQ«¥\Zó:£eãzÝ\034\017µ\037¹Û²?=\ÝÃ"
[17] "ëp'Öò[ésÝÞý‹Ã\v{ΤÝp\005AŽD7¢\033U\0219æ~\u008d@—\020R?ûkÑ\u008d¬äÜ«¼Ð·ê\0209Ö\020Ý_¯ä\021\026ä¤n¡×â'và˳áuGÉC¼³;9jNrÌÝ\006u1ºLòz\024uw‰I‰æ\036C”ÿqF©ªá­äÓÒîc\030àé
=H|ÛO4\fµƒålÊÝØý©ÝkÉ;®¦\030™PI¨\036Æ5çRâR®)eŸêx+ÕóýÝO\003ýA*é;\u0081øfZÑ" [18] "¹\fw 8Ã\tvµ$f‹kÊ䘔í\\iž\017n•äÂòÙåA\036²\030Éô®%[j‹)¾\u0081ZY\\Œd//\027Èå\u0090\024“¯¾ä\027ó(\030T<\022" [19] "¡X'ç\021gÖµ\f4˜šgbÜO©Egœ!º’R&ÍÙŸHϧZ¾¾Ú´[GƒiÉvϘ\016Ó+æ–o\vÀ\020î\034~mÿöªÔ¼-†’íJîþà:—¿ŠÍ´Ïdôù\a™&¸•Jû0-ñ¹TÌ‹I¿¿ûF&‹:ø(ÆMî‡ë\&T"
[20] "ƒwãqRË7\a º0\017\035®s‹#iSrõ\\\031\f¿âÚ\"6¦wgâL¾—–êrÜ\vD­¢J14h1TËö\026¦wq>±Œ—¼ÚÂM•U¶-±r­èð‘ýÀìy£ÙÕP9çóqu¯Æ1Ð\032þZ~8jlãžd’2.s\u0081\033©ºñ"
[21] "\020nÚÿê}¢Vüv\036Y€¬„î1¾¦zŽÍ‰ù0:~u"
[22] "?­'÷ñi~\037Æ\002\036\035Îeˆ7å«ÉØÕ(eÑuL~v}ÄZ“,ƒ§j”o\004Ñ«!.¹’°\032àä\021Ú£/äa"
[23] "\u008118[¡W‘\034äð\033²·ø^\u008dÀK‰ãü‡2g^ðLŒ±Þб07¬…" [24] ".\025ãZ†ëwòÿ0\024ã¸" [25] "UóQ~crÓgHÅÙß?\\Î\024×£Ý\033û¯çÈÀHaã£\022BoãTP-¨6ãnŒùµÄŸÛý<\025ò;KQ\füÎáÊþ\\ŒýŸåÿV\024y&J¬Q\u008f¾À\023*›M‚Ò\aã\\\u008dl·ü¸z\030j/¥ÇäW(cþòU¢õü•×@•*\fôRtØý \020M£È÷8Ò®Õ¬¬+ŽK0Þn×UÇQKÛ\026Éh\034\026÷\u008f2þ>\023ªÀh@\037lÃÛh\005\ru–å°•
™ê\034%O\003åÓÜ·OWNGjs'×>­ì\v© &\027ihd6z¤û¶ñ§r\030ŠJg1Ï5NG60)‡\v\026r'<^Ïõ\u008d\034wqÀ‡ð"
[26] "#Øq\003ó8ÀXF‹%.\t~\002°!rÿ$s´îʨs\001H/˜"
[27] "[\036ó¹]”9“Éž@KÇ·f|&SJ§\f/\024\vˆÃ.Q—‚¡¢ù\f¬‡Š©ñÍ]êÅ—ù¦õ¾”WDD.\020òp´\"Ž\aÐŒ/\tê|:›¦ˆæÇ°\030[Ï\021Þ‘ä¦ß=<Žç½²¿ž–î•@ow­œÀÝÌCŸx&saå,ÏY^Š\týaZP]œÏ\017ºà×ö\u008f\002óAJ?H§÷K\u0081ýO\023ÛV¨$“Iy.lwåÕ•p$sI¯1òwœ¨]ÊŸ9j¥›»\034õºZ"
[28] "zÔ1\t\bQ=;¾„n\004P´\vÓB6WΩ¤Y\r\035\030“2f\003yñ R¨"
[29] "§\024˯½Ô\005\004ƒÁ}?¦øÇ1ÈOv\037§Ôåt;xë\vñ§àS²6îíä~?ê,gÊ–†‘ÀÆE%ø‹ÇæÔ\027´Z9æ¨M\033n\022y\fCóÜÿIçbD\u008fòdãLc\u008fc\006J3ÞÛåÕw@M;¼¹\\WdÖɵ÷’ï\u009dHóãÄ·,\034\003q¬g´£¼k’…½ô\030Ë^\\TÝK|5Wí5w\u008fåSêLý‘ÉpfQ=jÛL\020µÚ·,¨Õ°å»©Ú›äô\031ÝMåœ\024|?M#öúîkqÔ¿·û Uu$#OC¯âÀZ\005\032Yt®+Øœ·\022!¦ª¤†M©ÍY¦Z’\t×û$ß\032šÖOvÚ»\f·üt<\006›ò \027>q·cRæWBÒ‹kðb¿mÛFCsV ««½\004\005gç`•ØB1º'&\u009d\\u009dL3ªÍ%½\u009d¯%ê%’ÁÕeçëû/ï߈9\030SvüY.\aÇä.$\023U
qù{˜j÷“øæOâ\022>Ú}tÐI¼Ÿ#w1Û#îìþITùp÷•Àgæ§\016" [30] "ÿ\f\r\025\u009d\032*%\u008fR\001­»\021Zó:"
[31] "Ô¤ÛuHꃌ\rîÇœ.†\002æD|ŒJžV[ù•;dþíË»w2š¸œ.\031Ùø•ççi–»ÿK1?+} Ý^p/e\035ìó”#áÌ­&[ù\tÖC(Ž"
attr(,"status") [1] 99

gtatters commented 3 years ago

I don't know what you mean by "But if I use the same settings for a convertflirJPG() function call I get a whole mess of text with the main warning message"

convertflirJPG is not a simple wrapper for the system2 command. You'll have to be explicit in what your Thermimage question is. what exact code did you type. I can't replicate it without that

Jonathan-Gore commented 3 years ago

When I copy/paste and run the R convertflirJPG() function with your corrections I get that system2() error message.

convertflirJPG("C:/git/IR_60901.jpg", exiftoolpath="installed", res.in="464x348", endian="lsb", verbose=TRUE)

Warning message: In system2(exiftool, args = exifvalsrawunix, stdout = TRUE) : running command '"exiftool" "C:/git/IR_60901.jpg" -b -RawThermalImage | convert - gray:- | convert -depth 16 -endian msb -size 464x348 gray:- "C:/git/output/IR_60901.png"' had status 99

But interestingly enough if I just rip out the exiftool/Imagemagick CMD call that is being sent to the command prompt

"exiftool" "C:/git/IR_60901.jpg" -b -RawThermalImage | convert - gray:- | convert -depth 16 -endian msb -size 464x348 gray:- "C:/git/output/IR_60901.png"

I actually get a successful conversion! So although the core of each command is the same, I only get the error when running it through convertflirJPG(), while a "raw" exiftool/Imagemagick command line call without R involved at all garners a successful conversion. You've been very helpful and I've just made a small function to directly run exiftool without the convertflirJPG() function!

Thanks so much for troubleshooting, user error as per usual.

gtatters commented 3 years ago

Aha, one reason I added the verbose=TRUE was to allow users to troubleshoot. Often these system call errors are based on differences in OS that are difficult for me to troubleshoot or keep up with. I will try to get onto a windows machine and try this out so I can replicate the problem and work backwards.

Jonathan-Gore commented 3 years ago

Awesome,

If you don't mind me asking, what does the middle Imagemagick convert call do?

convert - gray:-

I understand the first exiftool call converts the FLIR jpg into binary data

"exiftool" "C:/git/IR_60901.jpg" -b -RawThermalImage

and that the last Imagemagick call actually completes the conversion into a png,

convert -depth 16 -endian msb -size 464x348 gray:- "C:/git/output/IR_60901.png"

but what happens in the middle? Does the last Imagemagick call not additionally convert the data to grayscale with 'gray:-' ?

gtatters commented 3 years ago

The author of Exiftool gave me some pointers in the EEVBlogs that I consulted during the function creation stage.

The way I understand (but it has been >4 years since I worked on this code) it is this: Exiftool extract the raw thermal image in whatever manner FLIR has stored it in the JPG. Sometimes they have stored in a TIFF format, sometimes as PNG. So the first convert following the pipe from exiftool just instructs it to convert to a gray scale image (maybe I added it for safety, or maybe it is required before the second convert call following the second pipe. This convert call is important for for setting the endian and 16 bit depth and resolution.

Here is a link to the eevblog that really helped with the cmd line code: https://exiftool.org/forum/index.php?PHPSESSID=a3fb7c3fd1233b33c6eaef613d2ee08b&topic=4898.0