class SKImage{ Node H, S, L; Color colorObj; //-------------------- SKImage(PImage img){ colorObj = new Color(); int w = img.width; int[][] HMap = new int[w][w]; int[][] SMap = new int[w][w]; int[][] LMap = new int[w][w]; img.loadPixels(); for(int i=0 ; i1){ subdivide = true; int ch = cellSize/2; nodes = new Node[4]; nodes[0] = new Node(valueMap, x , y , ch); nodes[1] = new Node(valueMap, x+ch, y , ch); nodes[2] = new Node(valueMap, x , y+ch, ch); nodes[3] = new Node(valueMap, x+ch, y+ch, ch); } else{ subdivide = false; value = valueMap[x][y]; } } //-------------------- int get(int i, int j){ int ch = cellSize/2; if(!subdivide) return value; if(i< x+ch && j< y+ch) return nodes[0].get(i,j); if(i>=x+ch && j< y+ch) return nodes[1].get(i,j); if(i< x+ch && j>=y+ch) return nodes[2].get(i,j); if(i>=x+ch && j>=y+ch) return nodes[3].get(i,j); return 0; } //-------------------- void calculateExtremes(){ if(subdivide){ nodes[0].calculateExtremes(); nodes[1].calculateExtremes(); nodes[2].calculateExtremes(); nodes[3].calculateExtremes(); maxVal = max( max(nodes[0].maxVal,nodes[1].maxVal) , max(nodes[2].maxVal,nodes[3].maxVal) ); minVal = min( min(nodes[0].minVal,nodes[1].minVal) , min(nodes[2].minVal,nodes[3].minVal) ); } else maxVal = minVal = value; } //-------------------- void calculateAverages(){ if(subdivide){ nodes[0].calculateAverages(); nodes[1].calculateAverages(); nodes[2].calculateAverages(); nodes[3].calculateAverages(); value = ( nodes[0].value + nodes[1].value + nodes[2].value + nodes[3].value )/4; } } //-------------------- void compress(int threshold){ if(subdivide){ nodes[0].compress(threshold); nodes[1].compress(threshold); nodes[2].compress(threshold); nodes[3].compress(threshold); if( (maxVal-minVal) <= threshold){ nodes = null; subdivide = false; } } } }