public static int[][] trimWhiteColumns(int[][] seg){

		boolean blackFlag = false;
		int noOfRows = seg.length;
		int noOfColumns = seg[0].length;
		ArrayList<Integer> emptyCols = new ArrayList<>();
		int[][] segment = null;
		
		// find a column with no foreground pixel.
		for(int i = 0; i<noOfColumns; i++){			
			blackFlag = false;
			for(int j = 0; j<noOfRows; j++ ){
				
				if(seg[j][i]==1){
						blackFlag = true;
						break;
				}
			}
			if(!blackFlag){
				emptyCols.add(i);
			}
		}
		
		// make and save the segment to the arrayList
		int noOfColmInsegment = noOfColumns - emptyCols.size();
		
		if(noOfColmInsegment > 1){
			segment = new int[noOfRows][noOfColmInsegment];
			
			for(int rownum = 0; rownum < noOfRows; rownum++){
				
				int currentCol = 0;
				for(int colnum = 0; colnum < noOfColumns; colnum++){
					
					if(!emptyCols.contains(colnum)){
						segment[rownum][currentCol++] = seg[rownum][colnum];
					}
				}
			}
		}
		return segment;
	}