Hi,
I’m trying to make a two thresholds color analisis in a Pimage file.
But I can’t understand what I wrote wrong or If I made a conceptual mistake.
I’m a bit lost now.
for(int i =0; i<imgOrigin.pixels.length; i++){
if(imgOrigin.pixels[i] >= cpLow.getColorValue() && imgOrigin.pixels[i]<= cpHigh.getColorValue()){
imgUpdated.pixels[i] = myred;
println("Inside");
}
else{
imgUpdated.pixels[i] = imgOrigin.pixels[i];
}
};
I can’t understand why when I move the blue and or green sliders
I can’t make the imgUpdated.pixels[i] = myred;
(I’m not interested in aplha value, so they will be always at 255 )
for instance with:
LOW: -16777216 = rgb = 0
HIGH: -16711936 = r =0 g =255 b=0
Theorically if in the image there are green values they will be red…
but it’s not like that at all.
Ok, there is something about using the “pure” values that is not very clear to me.
But anyway there are 65280 values from the low and the high so I should see something.
like the println(“Inside”);
or is just the file that is not optimal for this kind of analisis?!?!
here the code:
PImage imgOrigin,imgUpdated;
int low =0;
int high = 0;
color myred = color(255, 0, 0,255);
void setup(){
imgOrigin = loadImage("sunflower.jpg");
imgUpdated = createImage(imgOrigin.width,imgOrigin.height,RGB);
size(400,400);
// load image onto surface - scale to the available width,height for display
// so it's very stretchd
image(imgOrigin, 0, 0, width, height);
uiSetupColor();
}
void draw(){
uiDraw();
// We are going to look at both image's pixels
imgOrigin.loadPixels();
imgUpdated.loadPixels();
for(int i =0; i<imgOrigin.pixels.length; i++){
if(imgOrigin.pixels[i] >= cpLow.getColorValue() && imgOrigin.pixels[i]<= cpHigh.getColorValue()){
imgUpdated.pixels[i] = myred;
println("Inside");
}
else{
imgUpdated.pixels[i] = imgOrigin.pixels[i];
}
};
imgUpdated.updatePixels();
image(imgUpdated, 0, 0, width, height);
}
void keyPressed(){
if(key == 's' || key == 'S'){
imgUpdated.save("trashold"+".jpg");
println("Saved");
}
}
tab colorControl
import controlP5.*;
ControlP5 cp5;
ColorPicker cpLow,cpHigh; ;
void uiSetupColor() {
cp5 = new ControlP5(this);
cpLow = cp5.addColorPicker("low")
.setPosition(20, 20)
.setColorValue(color(0, 0, 0, 255))
;
cpHigh = cp5.addColorPicker("high")
.setPosition(20, 100)
.setColorValue(color(0, 0, 0, 255))
;
}
void uiDraw(){
println("LOW: "+cpLow.getColorValue() +" HIGH: " +cpHigh.getColorValue());
//textSize(16);
//text("Low: "+ cpLow.getColorValue(),20, 16);
//text("High: "+ cpHigh.getColorValue(),20, 96);
}
public void controlEvent(ControlEvent c, ControlEvent d) {
// when a value change from a ColorPicker is received, extract the ARGB values
// from the controller's array value
if(c.isFrom(cpLow)) {
int r = int(c.getArrayValue(0));
int g = int(c.getArrayValue(1));
int b = int(c.getArrayValue(2));
int a = int(c.getArrayValue(3));
color col = color(r,g,b,a);
}
if(d.isFrom(cpHigh)) {
int r = int(c.getArrayValue(0));
int g = int(c.getArrayValue(1));
int b = int(c.getArrayValue(2));
int a = int(c.getArrayValue(3));
color col = color(r,g,b,a);
println("event \talpha:"+a+"\tred:"+r+"\tgreen:"+g+"\tblue:"+b+"\tcol_HIGH "+col);
}
}
thanks
R_colors