void DrawContoursAroundSegments(int[] ubuff, int[] labels, int width, int height, @SuppressWarnings("unused") int color) {
        int[] dx8 = {-1, -1, 0, 1, 1, 1, 0, -1};
        int[] dy8 = {0, -1, -1, -1, 0, 1, 1, 1};
        
        int sz = width * height;

        boolean[] istaken = new boolean[sz];
        int[] contourx = new int[sz];
        int[] contoury = new int[sz];
        
        for (int i = 0; i < sz; i++) {
            istaken[i] = false;
        }

        int mainindex=0, cind=0;
        for (int j=0; j<height; j++) {
            for (int k=0; k<width; k++) {
                    int np = 0;
                    for (int i=0; i<8; i++) {
                        int x = k + dx8[i];
                        int y = j + dy8[i];

                        if ((x>=0 && x<width) && (y>=0 && y<height)) {
                            int index = y*width + x;
                             //if (false == istaken[index])//comment this to obtain internal contours
                               {   if (labels[mainindex] != labels[index]) {
                                   np++;
                            	   }
                               }
                        }
                    }
                    if (np > 1) {
        				contourx[cind] = k;
        				contoury[cind] = j;
        				istaken[mainindex] = true;
        				//img[mainindex] = color;
        				cind++;
        			}
        			mainindex++;
        	}
        }

    	int numboundpix = cind;//int(contourx.size());
    	for( int j = 0; j < numboundpix; j++ ) {
    		int ii = contoury[j]*width + contourx[j];
    		ubuff[ii] = 0xffffff;
    		for( int n = 0; n < 8; n++ ) {
    			int x = contourx[j] + dx8[n];
    			int y = contoury[j] + dy8[n];
    			if( (x >= 0 && x < width) && (y >= 0 && y < height) ) {
    				int ind = y*width + x;
    				if(!istaken[ind]) ubuff[ind] = 0;
    			}
    		}
    	}
    }