Ask Your Question
0

associate a string to a pixel

asked 2012-12-12 06:03:06 -0500

federiko00 gravatar image

Hi everybody, i have an image with many colors,one for pixel and I would associate a string to every pixel to specify the color's name;is there a way to do this? Thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2012-12-12 06:34:07 -0500

Haris gravatar image

updated 2012-12-12 06:47:15 -0500

I think you have predefined string for each pixel value, if I right you can solve this by accessing each pixel in the image using following piece code

for(int i=0; i<src->height; i++)      
{
  for(int j=0; j<src->width; j++)    
   {   

    CvScalar pix=cvGet2D(src,i,j); // pix.val[0]->Blue channel
                                   // pix.val[1]->Green channel
                                   // pix.val[2]->Red channel    
   } 
 }

By comparing each pixel value you can find the colours of corresponding pixel. I hope this is what your are looking for.

edit flag offensive delete link more

Comments

i'm using c++,my image is Mat type and cvGet2D doesn't accept it as an argument!!however,once i do this,how can i associate a string? e.g. : first pixel is R:0 G:1 B:91 and the string is "very very dark blue"

federiko00 gravatar imagefederiko00 ( 2012-12-12 07:19:13 -0500 )edit

For C++ see this link http://stackoverflow.com/questions/7899108/opencv-get-pixel-information-from-mat-image. So do you have per-defined string for each pixel combination?

Haris gravatar imageHaris ( 2012-12-12 22:59:17 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-12-12 06:03:06 -0500

Seen: 80 times

Last updated: Dec 12 '12