I didn’t realize that you had attached your question to an eight-year-old Post that I posted at least two “solutions” to eight years ago! In the Forums, we call this “Hijacking a Post”. I apologize for not noticing this earlier, and asking you to start a “New topic”, but I’m going to do this now!
Please do not Reply to this Post. Please start a New Topic. I regret to say that looking at the code you did attach (thank you for that!), it does not help me to understand your problem, possibly because you and I are using slightly different terminology (and possibly speak different native languages).
I do not understand what sort of Image Processing you are trying to do. Note that the Topic of this Post (as expressed by its Title) is how to extract, from an RGB color Image, the Red Plane. I showed how to extract the R, G, and B planes, then recombine then again to reconstruct the original Image.
When you Post your “New Topic”, please give it a title that explains, in a few words, what you are trying to do. Are you “extracting a color plane” from a color image? Are you attempting to “colorize” a GrayScale image? Get the Title of your Post to say (in less than 20 words) what you need to do.
In your Post, explain what your input image is, what you want to do with the image, and what you want the output image (or images) to be. I am not an “image processor” – I have no idea what a “dehazed image in grayscale” means. To me, “grayscale” means “intensity only, no color information”. An RGB Image has 32-bit pixels, with three 8-bit “color channels”, whereas gray scale images have 8- (or 16-) bit “shades-of-gray” (or “intensity”) values.
Make clear what kind of images are your inputs, and outputs, and how you want to transform your images as they go from Input to Output. It might be a good idea to actually attach an input image and (if possible) the corresponding output image you are trying to achieve. Once we know what you want to do (and, perhaps, have a “sample” of the data you are using), we can be more helpful.
But do start a new Post.
Bob Schor