UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Adventurer
Adventurer
12,398 Views
Registered: ‎01-16-2015

Output of hls::CvtColor<HLS_GRAY2RGB> appears gray scale.

Jump to solution

Hi,

 

I want to use the function hls::CvtColor<HLS_GRAY2RGB>(img_1_g, img_2_rgb) in my code.


This is my image_filter function in top.cpp file:

 

void image_filter(AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM, int rows, int cols)
{
//Create AXI streaming interfaces for the core
#pragma HLS INTERFACE axis port=INPUT_STREAM
#pragma HLS INTERFACE axis port=OUTPUT_STREAM
#pragma HLS RESOURCE core=AXI_SLAVE variable=rows metadata="-bus_bundle CONTROL_BUS"
#pragma HLS RESOURCE core=AXI_SLAVE variable=cols metadata="-bus_bundle CONTROL_BUS"
#pragma HLS RESOURCE core=AXI_SLAVE variable=return metadata="-bus_bundle CONTROL_BUS"
#pragma HLS INTERFACE ap_stable port=rows
#pragma HLS INTERFACE ap_stable port=cols
hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC3> img_1_rgb(rows, cols);
hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC3> img_2_rgb(rows, cols);
GRAY_IMAGE img_1_g(rows, cols);
GRAY_IMAGE img_2_g(rows, cols);
GRAY_IMAGE img_3_g(rows, cols);
#pragma HLS dataflow
hls::AXIvideo2Mat(INPUT_STREAM, img_1_rgb);
hls::CvtColor<HLS_RGB2GRAY>(img_1_rgb, img_1_g);
hls::CvtColor<HLS_GRAY2RGB>(img_1_g, img_2_rgb);
hls::Mat2AXIvideo(img_2_rgb, OUTPUT_STREAM);
}

 


where I have typedef of RGB_IMAGE and GRAY_IMAGE in top.h as:

 

typedef hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC3> RGB_IMAGE;
typedef hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC1> GRAY_IMAGE;

 

I don't get any errors during C Synthesis nor C Simulation. 

The output of this code seems to be gray scale image. (While viewing the output in IrfanView, the output image is 8 BPP)
It is not converted back to RGB. What would the possible reasons be? Maybe there's something wrong with the way I'm writing the output of hls::CvtColor<HLS_GRAY2RGB> into the output file. However, I have tested other functions like hls::GaussianBlur() and hls::Erode(), they all seem to give proper outputs. The issue is only when the output is supposed to be RGB.

 

Any suggestions?

 

Regards,

 

Meghana.

0 Kudos
1 Solution

Accepted Solutions
Observer maddiott
Observer
21,406 Views
Registered: ‎04-30-2014

Re: Output of hls::CvtColor<HLS_GRAY2RGB> appears gray scale.

Jump to solution
RGB2GRAY extracts the gray scale information from the three channel image and puts it into a single channel image. The GRAY2RGB simply clones the single channel into each of the three channels of a color image. So not only is a gray image unsurprising, it's the expected behavior.
0 Kudos
8 Replies
Observer maddiott
Observer
21,407 Views
Registered: ‎04-30-2014

Re: Output of hls::CvtColor<HLS_GRAY2RGB> appears gray scale.

Jump to solution
RGB2GRAY extracts the gray scale information from the three channel image and puts it into a single channel image. The GRAY2RGB simply clones the single channel into each of the three channels of a color image. So not only is a gray image unsurprising, it's the expected behavior.
0 Kudos
Adventurer
Adventurer
12,374 Views
Registered: ‎01-16-2015

Re: Output of hls::CvtColor<HLS_GRAY2RGB> appears gray scale.

Jump to solution

If it clones the single channel into each og the R, G and B channles, I am supposed to get a 24 BPP image when viewed in Irfan View, right? Is there any parameter I have to change while writing my output into a file? Or is there any other way by which I can confirm that it is a 24 BPP image?

 

0 Kudos
Explorer
Explorer
12,366 Views
Registered: ‎09-02-2013

Re: Output of hls::CvtColor<HLS_GRAY2RGB> appears gray scale.

Jump to solution

I'm guessing you are saving the image in the testbench with imwrite() ?

 

Try initiating the variable in the test bench as a 3 channel image with Mat::zeros before you save it.

For example:

hls_result = Mat::zeros(imL_hls.rows, imL_hls.cols, CV_8UC3);
AXIvideo2cvMat(axi_dst, hls_result);
imwrite(IMG_OUT_HLS, hls_result);

 

For me this saves a .bmp image that is 3 times bigger than the image I compare it with which I didn't initiate.

0 Kudos
Adventurer
Adventurer
12,360 Views
Registered: ‎01-16-2015

Re: Output of hls::CvtColor<HLS_GRAY2RGB> appears gray scale.

Jump to solution

Well, I don't use Mat. This is what I am doing:

 

IplImage* Final2_Dest;  // outiside main()

 

Final2_Dest=cvCreateImage(cvGetSize(src2), 8, 3);
AXI_STREAM  Final2_Dest_axi;
image_filter(src2_axi, Final2_Dest_axi,src2->height, src2->width);
AXIvideo2IplImage(Final2_Dest_axi, Final2_Dest);
cvSaveImage(OUTPUT_IMAGE,Final2_Dest);

 

where OUTPUT_IMAGE has the path defined in top.h as:

#define OUTPUT_IMAGE  "<path>"

 

 

 

When I tried whatever you said, I got this error during C Simulation:

 

 

0 Kudos
Adventurer
Adventurer
12,353 Views
Registered: ‎01-16-2015

Re: Output of hls::CvtColor<HLS_GRAY2RGB> appears gray scale.

Jump to solution

Sorry, the screenshot I had inserted isn't seen in my previous message.
The error is this:

 

error.png

0 Kudos
Explorer
Explorer
12,345 Views
Registered: ‎09-02-2013

Re: Output of hls::CvtColor<HLS_GRAY2RGB> appears gray scale.

Jump to solution

Why are you not using the C++ API for opencv? IplImage is old and deprecated. I suggest using the cv namespace

 

#include "opencv2/opencv.hpp"

using namespace cv;

 or use cv:: as prefix for functions etc. just like you are doing with hls:: (this also means you could use "using namespace hls;" if you don't want to write hls:: in front of every hls function)

Adventurer
Adventurer
12,331 Views
Registered: ‎01-16-2015

Re: Output of hls::CvtColor<HLS_GRAY2RGB> appears gray scale.

Jump to solution

I got an error initially when I used the C++ OpenCV functions. That's why I stuck to this. Anyway, thanks. Now since this problem is fixed, I think I'll try it with C++ APIs.

0 Kudos
Moderator
Moderator
12,271 Views
Registered: ‎04-17-2011

Re: Output of hls::CvtColor<HLS_GRAY2RGB> appears gray scale.

Jump to solution
@meghanadk As the issue is resolved, please close this thread as Solved and mark the post which helped you as an Accepted Solution.
Regards,
Debraj
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
0 Kudos