?
Solved

unexpected result

Posted on 2007-08-06
14
Medium Priority
?
383 Views
Last Modified: 2013-11-05
I wanted someone to help interpret my results as I don't really understand them. I created an LUT table that is applied to the Hue vales of a matrix. It works fine, isolates the desired range of colors. Now, if I fill the table with the range of color (100 - 120) and the rest of the table with 255 instead of 0, the image is then inverted. It goes from a light object in black background to a black object in white background once the other non-range values are changed from 0 to 255.  It's a desirable result but I don't understand it because the cvLUT function states that it will index pixels only  in the range. So why does a hue value of 255 cause inversion? Not to mention that the Hue value is multiplied by 2 with reconstruction of the image (Hue is divided  by 2 to fit into an 8bit number.

Thanks WLE
0
Comment
Question by:Wanderinglazyeye
  • 5
  • 4
  • 4
  • +1
14 Comments
 
LVL 22

Expert Comment

by:grg99
ID: 19637839
How about you show us the table.  it's not clear from your description what it contains.

0
 
LVL 53

Expert Comment

by:Infinity08
ID: 19637852
Are you sure that it's inverted or does it only look like it is ? In other words, it's probably only the background that changes from black to white, and the other colors (100-120 range) stay the same, but just look lighter/darker depending on the background. That's called an optical illusion ... can you check that that's not the case ?
0
 
LVL 86

Expert Comment

by:jkr
ID: 19638045
That is pretty much the result that you should expect. Is the region [100;120] different regarding the outcome when doing so? If not everything is the way it should be.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Wanderinglazyeye
ID: 19638507
The region [100;120] is not the same. When I run it with the table of the range [100;120] and 0 in all other places, the background is black and the red objects are white. When I add the LUT table (below) the background is white and the range is dark. I rechecked it.


White background/ dark objects

255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      101      102      103      104      105      106      107      108      109      110      111      112      113      114      115      116      117      118      119      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255      255

Dark objects/white background:
Writing sat val to a file.
0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      101      102      103      104      105      106      107      108      109      110      111      112      113      114      115      116      117      118      119      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      

Any further thougts??
0
 
LVL 86

Expert Comment

by:jkr
ID: 19638560
Hmm, from the docs:

 /*F///////////////////////////////////////////////////////////////////////////////////////
 //    Name:    cvLUT
 //    Purpose: Performs lookup-table transform: dst(x,y) = lut[src(x,y)]
 //    Parameters:
 //      srcarr - the source array: 8u or 8s type
 //      dstarr - the destination array of arbitrary type,
 //      lutarr - the LUT array. The same type as the destination array,
 //               contains 256 entries.
 //    Note:
 //      if the source array has 8s type, the modified formula is used:
 //      dst(x,y) = lut[src(x,y) + 128]
 //F*/
 OPENCVAPI  void cvLUT( const CvArr* srcarr, CvArr* dstarr, const CvArr* lutarr );

Especially

 //    Note:
 //      if the source array has 8s type, the modified formula is used:
 //      dst(x,y) = lut[src(x,y) + 128]

seems to play a role here. What are the results for other values but '0' and '255'?
0
 

Author Comment

by:Wanderinglazyeye
ID: 19638627
Ok, it looks like the pixel values of the Hue image  in the table with the white background (255) is being written as -1, which is unexpected. I do know that the Hue value is divided by 2 upon conversion to fit in an 8 bit value. 255 is 8bit, but must exceed some threshhold, becuase you can't have a Hue (upon conversion back to BGR of 510 - it doesn't exist).  So why is the cvLUT function writing a (-1) pixel value when the LUT has a value of 255?
0
 
LVL 86

Accepted Solution

by:
jkr earned 1200 total points
ID: 19638705
255 (unsigned) equals -1 (signed) as in terms of a 2's complement: http://en.wikipedia.org/wiki/Two%27s_complement
0
 

Author Comment

by:Wanderinglazyeye
ID: 19639794
>>>>>>>>seems to play a role here. What are the results for other values but '0' and '255'?

If I use 250 instead of 255 the filling number is -6. The isolated color values are between 100 - 120 as expected. I guess my question can be narrowed to this: if pixels are indexed only if they fall in the range of 100-120, why are non-range pixels being indexed at all such as in the case of -1 or -6? I don't mean to press the question, but this is really interesting to me this behavior. It can be manipulated. Are all pixels being indexed?
0
 
LVL 86

Expert Comment

by:jkr
ID: 19639853
Are ypu passing a signed or unsigned byte array?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 19639979
Your example shows the expected behavior, so there must be something I'm missing ... Which values are incorrect ? And in which cases ?
0
 

Author Comment

by:Wanderinglazyeye
ID: 19641373
From OpenCV:

The function cvLUT fills the destination array with values from the look-up table.
----------------------------------------------------------------------------------------------------

The LUT is an unsigned array. The source array to which the LUT array is being applied is unsigned as well.

0
 
LVL 53

Expert Comment

by:Infinity08
ID: 19641461
>> The LUT is an unsigned array. The source array to which the LUT array is being applied is unsigned as well.

And the destination array ? Is that also unsigned ?
0
 

Author Comment

by:Wanderinglazyeye
ID: 19641606
Let me correct:I don't whether the source array is unsigned or signed. Sorry. This array is generated by cvPixToPlane which takes an BGR picture and splits it into 3 planes - H, S, V (Hue, Saturation and Value). I am then applying  seperate LUT arrays(unsigned) to each plane to a destination array (allocated as unsigned).
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 800 total points
ID: 19643705
Well, first make sure whether the source array is signed or unsigned. Can you show the code that created it (including the original image) ?

I would still like to see a complete example of what's going wrong. So far, it seems like everything is as expected, so I must be missing something.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question