counting whites ( code) :
counting white pixels, and percentage, and then calculating the bound of white...
an interesting problem , but I never was able to fix the lower vertical bound.
but starting to see the ease for doing motion tracking and blob calculation.
|
// -- COUNTING WHITE PIXELS --
white_count = 0;
for (int i = 0; i < texW*texH; i++){
if (pixels[i] > mouseX*0.5f){
texPixels[i] = 255;
white_count++;
} else {
texPixels[i] = 0;
}
}
white_percentage = int(100*white_count/(texH*texW));
// -- WHITE PIXEL BOUNDS --
miny = texH;
minx = texW;
maxy, maxx = 0;
for(int i = 0; i < texW; i++){
for(int j = 0; j < texH; j++){
//if(texPixels[i * texH + j] == 255){
if(texPixels[j*texW + i] == 255){
if(maxy < j){
maxy = j; // <-- this value ain't working ???
}
if(maxx < i){
maxx = i;
}
if(miny > j){
miny = j;
}
if(minx > i){
minx = i;
}
}
}
}
|
image processing ( code) :
averaging, contrasting, multiplying... sample is 15 Mandalas (all 350x350).
well, some interesting results for the first three, but doing multiplication with more than 2 images is a bit tricky,
something I'll have to revisit another time. actually one of the biggest challenges
was figuring out how to load and allocate an array of images.
can't wait to get into color filtering / processing.
- 1
- 2
- 3
- 4
|
// inside the update() function
float pctX = (float)mouseX / (float)ofGetWidth();
float pctY = (float)mouseY / (float)ofGetHeight();
for (int i = 0; i < texW; i++){
for (int j = 0; j < texH; j++){
for (int k=0; k < num_img; k++){
// -- 1. averaging --
TexPixels[0][j * texW + i] += (inv_img) * Pixels[k][j * texW + i];
// -- 2. contrasting (variable) --
if (Pixels[k][j * texW + i] > 127){
TexPixels[1][j * texW + i] = MIN(255,
TexPixels[1][j * texW + i] + (inv_img) * Pixels[k][j * texW + i] + 255*pctX);
}else{
TexPixels[1][j * texW + i] = MAX(0,
TexPixels[1][j * texW + i] - (inv_img) * Pixels[k][j * texW + i] - 255*pctY);
}
// -- 3. contrasting + variable threshold --
if (Pixels[k][j * texW + i] > int(255*pctY)){
TexPixels[2][j * texW + i] = MIN(255,
TexPixels[2][j * texW + i] + (inv_img) * Pixels[k][j * texW + i] + 255*pctX);
}else{
TexPixels[2][j * texW + i] = MAX(0,
TexPixels[2][j * texW + i] - (inv_img) * Pixels[k][j * texW + i] - 255*pctX);
}
}
// -- 4. 2-image multiplying (variable) --
int t_var = int(pctY*12);
float per_multi = float(Pixels[t_var][j * texW + i])/255.0f;
TexPixels[3][j * texW + i] = MIN(255*pctX,
Pixels[t_var + 1][j * texW + i] * per_multi);
}
}
|