Loading ...
Sorry, an error occurred while loading the content.

Detecting black color segmentation

Expand Messages
  • tencuid
    Hello, I need to detect black objects in an image, but EasyTrain tool doesn t allow me to select black pixels to create a threshold file (.tm) with that color
    Message 1 of 2 , Jan 30, 2006
    View Source
    • 0 Attachment
      Hello,
      I need to detect black objects in an image, but EasyTrain tool
      doesn't allow me to select black pixels to create a threshold file
      (.tm) with that color inside. As *.tm files are binary, is there any
      other way to add black color in the threshold file?. Thanks a lot for
      your help.
    • Ethan Tira-Thompson
      ... Ah, this is tricky because all shadows look black, so you re likely to see it a lot of places that don t corresponding to a particular object. So there are
      Message 2 of 2 , Jan 30, 2006
      View Source
      • 0 Attachment
        tencuid wrote:
        Hello,
             I need to detect black objects in an image, but EasyTrain tool
        doesn't allow me to select black pixels to create a threshold file
        (.tm)  with that color inside. As *.tm files are binary, is there any
        other way to add black color in the threshold file?. Thanks a lot for
        your help.
        Ah, this is tricky because all shadows look black, so you're likely to see it a lot of places that don't corresponding to a particular object.  So there are built in thresholds in easytrain that mark the very brightest and very darkest areas of color space as unclassified.

        If you really want to select white or black as its own color, you'll have to write a bit of code to generate a manual threshold map... it's a very simple format:

        The header is:
        TMAP
        YUV8
        16 64 64

        Then followed by 64K lookup table, in Y, U, and V order.  As the numbers in the last row of the header indicate, the table stores 16 levels of Y, and 64 of U and V.

        So for instance, if you mark Y values 0-31 as index 1 (which then should be named "black" in the corresponding .col file), then this bit of code should do it:
        #include <iostream>
        #include <fstream>
        using namespace std;
        
        int main(int argc, char** argv) {
            if(argc<2) {
                cout << "Usage: " << argv[0] << " outfile" << endl;
                return 2;
            }
            ofstream o(argv[1]);
            
            //I don't recommend changing these
            const unsigned int Y_LEVELS=16;
            const unsigned int U_LEVELS=64;
            const unsigned int V_LEVELS=64;
            
            //header
            o << "TMAP\nYUV8\n"<<Y_LEVELS<<" "<<U_LEVELS<<" "<<V_LEVELS<<endl;
            
            //lookup table -- in this example, set all of y levels 0 and 1
            // (real y values 0-31) to index 1
            for(unsigned int y=0; y<Y_LEVELS; y++) {
                for(unsigned int u=0; u<U_LEVELS; u++) {
                    for(unsigned int v=0; v<V_LEVELS; v++) {
                        if(y<=1)
                            o.put(1);
                        else
                            o.put(0); //by convention, unclassified is index 0
                    }
                }
            }
            
            return 0;
        }
        

        I haven't thoroughly tested this, but it should give you the idea... you might want to modify it to read in and modify a previous threshold produced by easytrain, or use it as is along with seg/ThresholdMerge to merge their output (see seg/{ThresholdMerge,ThresholdAdd,MoveIndex}.java for more examples.)

        -ethan

      Your message has been successfully submitted and would be delivered to recipients shortly.