{"action":"opened","issue":{"url":"https://api.github.com/repos/robotology/yarp/issues/569","labels_url":"https://api.github.com/repos/robotology/yarp/issues/569/labels{/name}","comments_url":"https://api.github.com/repos/robotology/yarp/issues/569/comments","events_url":"https://api.github.com/repos/robotology/yarp/issues/569/events","html_url":"https://github.com/robotology/yarp/issues/569","id":103754648,"number":569,"title":"Improve Yarp capability to write/read image files","user":{"login":"pattacini","id":3738070,"avatar_url":"https://avatars.githubusercontent.com/u/3738070?v=3","gravatar_id":"","url":"https://api.github.com/users/pattacini","html_url":"https://github.com/pattacini","followers_url":"https://api.github.com/users/pattacini/followers","following_url":"https://api.github.com/users/pattacini/following{/other_user}","gists_url":"https://api.github.com/users/pattacini/gists{/gist_id}","starred_url":"https://api.github.com/users/pattacini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pattacini/subscriptions","organizations_url":"https://api.github.com/users/pattacini/orgs","repos_url":"https://api.github.com/users/pattacini/repos","events_url":"https://api.github.com/users/pattacini/events{/privacy}","received_events_url":"https://api.github.com/users/pattacini/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/robotology/yarp/labels/Component:%20YARP_sig","name":"Component: YARP_sig","color":"207de5"},{"url":"https://api.github.com/repos/robotology/yarp/labels/Type:%20Enhancement","name":"Type: Enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-28T16:51:15Z","updated_at":"2015-08-28T16:51:15Z","closed_at":null,"body":"##### Preamble\r\n`Yarp` has several `write()` and `read()` routines to save and load image files.\r\n\r\nAt present we can write/read images of the following formats:\r\n- 8-bit (int) monochromatic images\r\n- 32-bit (float) monochromatic images\r\n- `RGB`/`BGR`/`RGBA` (int) color images\r\n\r\nFor each of the above image types `Yarp` exposes the corresponding API:\r\n```cpp\r\nbool file::write(const ImageOf<PixelMono> &src, const ConstString &dest);\r\nbool file::write(const ImageOf<PixelFloat> &src, const ConstString &dest);\r\nbool file::write(const ImageOf<PixelRgba> &src, const ConstString &dest);\r\nbool file::write(const ImageOf<PixelRgb> &src, const ConstString &dest);\r\nbool file::write(const ImageOf<PixelBgr> &src, const ConstString &dest);\r\nbool file::write(const Image& src, const ConstString& dest);\r\n\r\nbool file::read(ImageOf<PixelMono> &dest, const ConstString &src);\r\nbool file::read(ImageOf<PixelFloat> &dest, const ConstString &src);\r\nbool file::read(ImageOf<PixelRgba> &dest, const ConstString &src);\r\nbool file::read(ImageOf<PixelRgb> &dest, const ConstString &src);\r\nbool file::read(ImageOf<PixelBgr> &dest, const ConstString &src);\r\n```\r\n\r\nInterestingly, we have only the _write_ part for the generic `yarp::sig::Image` type, lacking of the _read_ counterpart. However, inspecting the body of the latter function we can see that, sadly, an `RGB` image gets always saved.\r\n\r\n```cpp\r\nbool file::write(const Image& src, const ConstString& dest) {\r\n    ImageOf<PixelRgb> img;\r\n    img.copy(src);\r\n    return write(img,dest);\r\n}\r\n```\r\n\r\nThe patch in https://github.com/robotology/yarp/commit/d76fa3ec28f0307ada530f9a53612a7e577e2915 attempts to expand such a behavior into:\r\n```cpp\r\nbool file::write(const Image& src, const ConstString& dest) {\r\n    int code=src.getPixelCode();\r\n    if ((code==VOCAB_PIXEL_MONO) || (code==VOCAB_PIXEL_MONO16))\r\n        return write(static_cast<const ImageOf<PixelMono>&>(src),dest);\r\n    else if (code==VOCAB_PIXEL_MONO_FLOAT)\r\n        return write(static_cast<const ImageOf<PixelFloat>&>(src),dest);\r\n    else if (code==VOCAB_PIXEL_BGR)\r\n        return write(static_cast<const ImageOf<PixelBgr>&>(src),dest);\r\n    else if (code==VOCAB_PIXEL_RGB)\r\n        return write(static_cast<const ImageOf<PixelRgb>&>(src),dest);\r\n    else if (code==VOCAB_PIXEL_RGBA)\r\n        return write(static_cast<const ImageOf<PixelRgba>&>(src),dest);\r\n    else {\r\n        ImageOf<PixelRgb> img;\r\n        img.copy(src);\r\n        return write(img,dest);\r\n    }\r\n}\r\n```\r\n\r\n##### Bunch of comments\r\n1. We should better exploit the object hierarchy of `yarp::sig::Image` to achieve the same goal in a much more standard OOP approach, though the design seems quite messy.\r\n2. We still don't have the chance to store the remaining image types.\r\n3. We definitely need the `file::read(Image&,...)` counterpart, otherwise `yarpdatadumper` is able to save generic images while `yarpdataplayer` remains unable to load a generic image from a file.\r\n\r\nNote that upon the increasing use of stereo vision, users will be likely requiring to store the exact format of images of types `int_mono` and `float_rgb`.\r\n\r\n##### Final Question\r\nWill `yarpdataplayer` be really able to read generic image and correctly populate an `yarp::sig::Image` object?\r\n\r\nIt seems that the files stored by means of `file::write()` APIs do not contain information on their actual types (needs for double check). That's quite bad since it'd force us to introduce such information alongside with the logged data.\r\n\r\nFinally, a quick glance at the routine devoted to save a float image reveals that the format appears to be quite non standard.\r\n\r\n/cc @vtikha "}}