private ImageProcessor regionTight(ImageProcessor region, double minBright, double minHeight, int width, int height){
//		region.resetMinAndMax();
//		ImageProcessor mask = region.convertToByteProcessor(true);
//		enhance.setNormalize(true);
//		enhance.stretchHistogram(mask, 1);
//		mask.blurGaussian(2.5);
//		mask.threshold(minBright);
//		mask = bwAreaOpen(mask, 1000);
//		mask.invert();
//		mask = bwAreaOpen(mask, 1000);
//		mask.invert();
//
//		ImageProcessor s = region.convertToFloatProcessor();
//		s.invert();
//		s.blurGaussian(3.0);
//		s.resetMinAndMax();
//		s.subtract(s.getMin());
//		s.resetMinAndMax();
//		if(s.getMax() > 0.0) s.multiply(1.0 / s.getMax());
//		
//		s.resetMinAndMax();
////		//ImageProcessor w = s.convertToByteProcessor(true);
		region = region.convertToFloat();
		region.resetMinAndMax();
		region.multiply(1.0 / region.getMax());
		region.resetMinAndMax();
		ImageProcessor w = new ByteProcessor(width, height);
//		//matlab version
		try{
			double[][] mat = new double[width][height];
			for(int i = 0; i < width; i++){
				for(int j = 0; j < height; j++){
					mat[i][j] = Float.intBitsToFloat(region.get(i,j));
				}
			}
	
		    processor.setNumericArray("region", new MatlabNumericArray(mat, null));
		    proxy.eval("minHeight = " + minHeight + ";");
		    proxy.eval("minBrightness = " + minBright + ";");
		    proxy.eval("mask = imfilter(imadjust(region), fspecial('gaussian', [5 5],2.5))> minBrightness;");
		    proxy.eval("mask = ~bwareaopen(mask,1000);");
		    proxy.eval("mask = ~bwareaopen(mask,1000);");
		    proxy.eval("s = imfilter(imcomplement(region),fspecial('gaussian',[20 20],3.0));");
		    proxy.eval("s = s - min(s(:));");
		    proxy.eval("s = s / max(s(:));");
		    proxy.eval("w = watershed(imhmin(s,minHeight));");
		    proxy.eval("Final = imfill(bwareaopen(mask & (w~=0), 200) , 'holes');");
		    boolean[] javaArray = (boolean[]) proxy.getVariable("Final");
		    for(int i = 0; i < height; i++){
		    	for(int j = 0; j < width; j++){
		    		boolean val = javaArray[i*width + j];
		    		w.set(j, i, val ? 255 : 0);
		    	}
		    }
		} catch (Exception e){
			e.printStackTrace();
			System.exit(0);
		}
		
//		/*
//		MaximumFinder mf = new MaximumFinder();
//		w = hMinima(w, (int) minHeight);	
//		w = mf.findMaxima(w, 1.0, 1.0, MaximumFinder.SEGMENTED , false, false);
//		*/
//		
//		w.threshold(0);
//		
//		mask.copyBits(w, 0, 0, Blitter.AND);
//		
//		mask = bwAreaOpen(mask, 200);
//		
//		fillHoles(mask);
//		return setLabels(mask);
//		return s;
//		return w;
		return setLabels(w);
		
	}