Re: [Boost-users] [Gil] TIFF file with mixed 8/16 bit channel

Hey Christian, Many thanks for your response, good luck with the fix and it would be marvellous if you are able to keep us posted on progress ... Meanwhile I have another TIFF file to hand (also generated by Photoshop) which has these characteristics: Colorspace: CMYK Depth: 16-bit Channel depth: cyan: 16-bit magenta: 16-bit yellow: 16-bit black: 15-bit alpha: 16-bit Let me know if you'd like a copy to test with. All the best, Corinna ... Corinna Kinchin email: ckinchin@datazone.com Datazone Ltd. Tel: +353 64 66 28964 Palm Gate, Greenane, Fax: +353 64 66 28965 Killarney, Co. Kerry, Ireland URL: http://www.miramo.com Datazone - makers of `Miramo', the automated publishing tool
Hi Corinna,
I have been busy trying to load your picture but some internals of the tiff reader doesn't allow for that right now. Hopefully I can fix soon.
I'm just downloading the latest boost version (am using 1.42 at the moment which doesn't seem to have the cymk16161688_image_t you refer to) and will try out your suggestion.
You have to build such image type. Here is how you do it:
typedef bit_aligned_image5_type< 16, 16, 16, 8, 8, cmyka_layout_t
::type image_t;
And this is almost certainly an RTFM question but how does one know which input image type to use? If you had a moment to point me in the right direction or to jot down an elegant code snippet to get me on the right track for reading different flavours of TIFF files I'd be eternally grateful ...
You could use a dynamic_image. See the dynamic_image extension.
Regards, Christian

Hi all, I have encountered a compilation error in Visual Studio 2010 that I can't find any information online about. The error is: error C2338: (is_same<typename Layout::color_space_t, gray_t>::value) It occurs when I call transform_pixels (..) on image views that are not grayscale. Below is example code that reproduces the error and I have attached the build output. If you comment out the first absolute difference call, the program compiles as expected. Also, if it helps, I was able to get similar code working intermittently by commenting the line and rebuilding, then un-commenting and building (not rebuilding). That made me think it may be something related to the template definitions during compile time and the previous build results effecting something. #include "stdafx.h" #include <boost/gil/image.hpp> #include <boost/gil/typedefs.hpp> using namespace boost::gil; template <typename Out> struct op_absoluteDifference { template <typename T> Out operator()(const T& in1, const T& in2) const { return Out(abs(in2-in1)); } }; template <typename SrcView1, typename SrcView2, typename DstView> void absoluteDifference(const SrcView1& src1, const SrcView2& src2, const DstView& dst) { typedef typename channel_type<DstView>::type dst_channel_t; transform_pixels(src1, src2, dst, op_absoluteDifference<dst_channel_t>()); } int _tmain(int argc, _TCHAR* argv[]) { rgb8_image_t img1(100,100); fill_pixels(view(img1), rgb8_pixel_t(0,0,0)); rgb8_image_t img2(100,100); fill_pixels(view(img2), rgb8_pixel_t(10,20,30)); rgb8_image_t img3(100,100); fill_pixels(view(img3), rgb8_pixel_t(0,0,0)); absoluteDifference(const_view(img1), const_view(img2), view(img3)); //causes compilation error C2338: (is_same<typename Layout::color_space_t, gray_t>::value) gray16_image_t img4(100,100); fill_pixels(view(img4), gray16_pixel_t(0)); gray16_image_t img5(100,100); fill_pixels(view(img5), gray16_pixel_t(10)); gray16_image_t img6(100,100); fill_pixels(view(img6), gray16_pixel_t(0)); absoluteDifference(const_view(img4), const_view(img5), view(img6)); return 0; } I'm very new to the library so I wouldn't be surprised if I was doing something incorrectly. I appreciate any help or guidance. Thank you for your time, Mark Mark Sapp Aeroflex O: 512-327-4401 x278 F: 512-327-3341 mark.sapp@aeroflex.com www.aeroflex.com Notice: This e-mail is intended solely for use of the individual or entity to which it is addressed and may contain information that is proprietary, privileged, company confidential and/or exempt from disclosure under applicable law. If the reader is not the intended recipient or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If this communication has been transmitted from a U.S. location it may also contain data subject to the International Traffic in Arms Regulations or U.S. Export Administration Regulations and cannot be disseminated, distributed or copied to foreign nationals, residing in the U.S. or abroad, without the prior approval of the U.S. Department of State or appropriate export licensing authority. If you have received this communication in error, please notify the sender by reply e-mail or collect telephone call and delete or destroy all copies of this e-mail message, any physical copies made of this e-mail message and/or any file attachment(s).

Hi Mark, On Mon, Nov 7, 2011 at 11:12 AM, Sapp, Mark <Mark.Sapp@aeroflex.com> wrote:
Hi all,
I have encountered a compilation error in Visual Studio 2010 that I can't find any information online about. The error is:
error C2338: (is_same<typename Layout::color_space_t, gray_t>::value) template <typename Out> struct op_absoluteDifference { template <typename T> Out operator()(const T& in1, const T& in2) const { return Out(abs(in2-in1)); } };
Constructing Out is your problem -- you're initializing a multi-channel pixel type (rgb8_pixel_t) with a single value. Either convert to a grayscale image before using calling absoluteDifference, or if you actually want the absolute difference across all channels, call static transform: #include <boost/gil/image.hpp> #include <boost/gil/typedefs.hpp> using namespace boost::gil; struct op_absoluteDifferenceChannel { template <typename T> T operator()(const T& in1, const T& in2) const { return T(abs(in2-in1)); } }; struct op_absoluteDifferencePixel { template <typename T> T operator()(const T& in1, const T& in2) const { T retVal; static_transform(in1, in2, retVal, op_absoluteDifferenceChannel()); return retVal; } }; template <typename SrcView1, typename SrcView2, typename DstView> void absoluteDifference(const SrcView1& src1, const SrcView2& src2, const DstView& dst) { typedef typename channel_type<DstView>::type dst_channel_t; transform_pixels(src1, src2, dst, op_absoluteDifferencePixel()); } int main() { rgb8_image_t img1(100,100); fill_pixels(view(img1), rgb8_pixel_t(0,0,0)); rgb8_image_t img2(100,100); fill_pixels(view(img2), rgb8_pixel_t(10,20,30)); rgb8_image_t img3(100,100); fill_pixels(view(img3), rgb8_pixel_t(0,0,0)); absoluteDifference(const_view(img1), const_view(img2), view(img3)); //causes compilation error C2338: (is_same<typename Layout::color_space_t, gray_t>::value) gray16_image_t img4(100,100); fill_pixels(view(img4), gray16_pixel_t(0)); gray16_image_t img5(100,100); fill_pixels(view(img5), gray16_pixel_t(10)); gray16_image_t img6(100,100); fill_pixels(view(img6), gray16_pixel_t(0)); absoluteDifference(const_view(img4), const_view(img5), view(img6)); return 0; } HTH, Nate

Hi Nate, Thanks for the help and quick response. It works great with your changes. Do you have any feedback about the way I'm using the library in that example code? I need to iterate through each pixel's channels, do you think there are more efficient ways for accomplishing that? Thanks again, Mark -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Nathan Crookston Sent: Monday, November 07, 2011 1:20 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [Gil] Unknown compilation error (VS10) Hi Mark, On Mon, Nov 7, 2011 at 11:12 AM, Sapp, Mark <Mark.Sapp@aeroflex.com> wrote:
Hi all,
I have encountered a compilation error in Visual Studio 2010 that I can't find any information online about. The error is:
error C2338: (is_same<typename Layout::color_space_t, gray_t>::value) template <typename Out> struct op_absoluteDifference { template <typename T> Out operator()(const T& in1, const T& in2) const { return Out(abs(in2-in1)); } };
Constructing Out is your problem -- you're initializing a multi-channel pixel type (rgb8_pixel_t) with a single value. Either convert to a grayscale image before using calling absoluteDifference, or if you actually want the absolute difference across all channels, call static transform: #include <boost/gil/image.hpp> #include <boost/gil/typedefs.hpp> using namespace boost::gil; struct op_absoluteDifferenceChannel { template <typename T> T operator()(const T& in1, const T& in2) const { return T(abs(in2-in1)); } }; struct op_absoluteDifferencePixel { template <typename T> T operator()(const T& in1, const T& in2) const { T retVal; static_transform(in1, in2, retVal, op_absoluteDifferenceChannel()); return retVal; } }; template <typename SrcView1, typename SrcView2, typename DstView> void absoluteDifference(const SrcView1& src1, const SrcView2& src2, const DstView& dst) { typedef typename channel_type<DstView>::type dst_channel_t; transform_pixels(src1, src2, dst, op_absoluteDifferencePixel()); } int main() { rgb8_image_t img1(100,100); fill_pixels(view(img1), rgb8_pixel_t(0,0,0)); rgb8_image_t img2(100,100); fill_pixels(view(img2), rgb8_pixel_t(10,20,30)); rgb8_image_t img3(100,100); fill_pixels(view(img3), rgb8_pixel_t(0,0,0)); absoluteDifference(const_view(img1), const_view(img2), view(img3)); //causes compilation error C2338: (is_same<typename Layout::color_space_t, gray_t>::value) gray16_image_t img4(100,100); fill_pixels(view(img4), gray16_pixel_t(0)); gray16_image_t img5(100,100); fill_pixels(view(img5), gray16_pixel_t(10)); gray16_image_t img6(100,100); fill_pixels(view(img6), gray16_pixel_t(0)); absoluteDifference(const_view(img4), const_view(img5), view(img6)); return 0; } HTH, Nate _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users Notice: This e-mail is intended solely for use of the individual or entity to which it is addressed and may contain information that is proprietary, privileged, company confidential and/or exempt from disclosure under applicable law. If the reader is not the intended recipient or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If this communication has been transmitted from a U.S. location it may also contain data subject to the International Traffic in Arms Regulations or U.S. Export Administration Regulations and cannot be disseminated, distributed or copied to foreign nationals, residing in the U.S. or abroad, without the prior approval of the U.S. Department of State or appropriate export licensing authority. If you have received this communication in error, please notify the sender by reply e-mail or collect telephone call and delete or destroy all copies of this e-mail message, any physical copies made of this e-mail message and/or any file attachment(s).

Hi Mark, On Mon, Nov 7, 2011 at 12:54 PM, Sapp, Mark <Mark.Sapp@aeroflex.com> wrote:
Hi Nate,
Thanks for the help and quick response. It works great with your changes. Do you have any feedback about the way I'm using the library in that example code? I need to iterate through each pixel's channels, do you think there are more efficient ways for accomplishing that?
Nope, what you've written seems like it should be efficient -- the images are constructed such that row-major iteration is most efficient, which is what transform_pixels does. The static_transform call in the code I sent actually unrolls the loop through the channels too. HTH, Nate P.S. See quoting guidelines: http://www.boost.org/community/policy.html#quoting

Hi Corinna, I'm sorry for getting back so late. In any event, your image you sent me caused some kind of trouble for us. But it's been now concluded that the image is just 8-bit all channels. Thanks to Mateusz who took the lead and even confirmed it on the libtiff mailing list. I started out assuming we have an heterogeneous 5 channel image and found some bugs along the way, which are fixed now. You can grab the latest from the repository. For now I suggest you read the image as follows: typedef bit_aligned_image5_type< 8, 8, 8, 8, 8, devicen_layout_t< 5 >
::type image_t; image_t img; read_image( "Shadow_cmyk8.tif", img, tiff_tag() );
I think it's fairly simple to added support for the cmyka colorspace and I'll try that as soon as I can. Let me know if you have any more troubles. Regards, Christian On Mon, Nov 7, 2011 at 5:02 AM, Corinna Kinchin <crin@datazone.com> wrote:
Hey Christian,
Many thanks for your response, good luck with the fix and it would be marvellous if you are able to keep us posted on progress ...
Meanwhile I have another TIFF file to hand (also generated by Photoshop) which has these characteristics:
Colorspace: CMYK Depth: 16-bit Channel depth: cyan: 16-bit magenta: 16-bit yellow: 16-bit black: 15-bit alpha: 16-bit
Let me know if you'd like a copy to test with.
All the best,
Corinna ...
Corinna Kinchin email: ckinchin@datazone.com Datazone Ltd. Tel: +353 64 66 28964 Palm Gate, Greenane, Fax: +353 64 66 28965 Killarney, Co. Kerry, Ireland URL: http://www.miramo.com
Datazone - makers of `Miramo', the automated publishing tool
Hi Corinna,
I have been busy trying to load your picture but some internals of the tiff reader doesn't allow for that right now. Hopefully I can fix soon.
I'm just downloading the latest boost version (am using 1.42 at the moment which doesn't seem to have the cymk16161688_image_t you refer to) and will try out your suggestion.
You have to build such image type. Here is how you do it:
typedef bit_aligned_image5_type< 16, 16, 16, 8, 8, cmyka_layout_t
::type image_t;
And this is almost certainly an RTFM question but how does one know which input image type to use? If you had a moment to point me in the right direction or to jot down an elegant code snippet to get me on the right track for reading different flavours of TIFF files I'd be eternally grateful ...
You could use a dynamic_image. See the dynamic_image extension.
Regards, Christian
participants (4)
-
Christian Henning
-
Corinna Kinchin
-
Nathan Crookston
-
Sapp, Mark