#2
by かずま » 7年前
Processing をインストールして、適当に書いてみました。
こんなもんでいいんでしょうか?
コード:
PImage img;
PImage img_r, img_g, img_b;
int[] hist_r = new int[256];
int[] hist_g = new int[256];
int[] hist_b = new int[256];
int histMax;
void setup()
{
size(640, 480);
img = loadImage("C:/Users/tomoh/OneDrive/Pictures/Drone.jpg");
img_r = createImage(img.width, img.height, RGB);
img_g = createImage(img.width, img.height, RGB);
img_b = createImage(img.width, img.height, RGB);
int sz = img.width * img.height;
for (int loc = 0; loc < sz; loc++) {
int r = (int)red(img.pixels[loc]);
int g = (int)green(img.pixels[loc]);
int b = (int)blue(img.pixels[loc]);
img_r.pixels[loc] = color(r, 0, 0); hist_r[r]++;
img_g.pixels[loc] = color(0, g, 0); hist_g[g]++;
img_b.pixels[loc] = color(0, 0, b); hist_b[b]++;
}
histMax = max(max(hist_r), max(hist_g), max(hist_b));
}
void draw()
{
int w = img.width / 3, h = img.height / 3;
image(img, w, 0, w, h);
image(img_r, 0, h, w, h);
image(img_g, w, h, w, h);
image(img_b, 2*w, h, w, h);
int y, b = (int)(img.height * 0.95);
for (int i = 0; i < 256; i++) {
int j = (int)map(i, 0, 256, 0, w);
y = (int)map(hist_r[j], 0, histMax, 0, h);
stroke(255, 255, 255, 128); line(j, b, j , b - y);
y = (int)map(hist_g[j], 0, histMax, 0, h);
stroke(255, 255, 0, 128); line(w + j, b, w + j , b - y);
y = (int)map(hist_b[j], 0, histMax, 0, h);
stroke(0, 255, 255, 128); line(2*w + j, b, 2*w + j , b - y);
}
}
このプログラムは、画像を 1枚しか読み込んでいないので、
2枚読み込むようにしたもの提示してください。
Processing をインストールして、適当に書いてみました。
こんなもんでいいんでしょうか?
[code]
PImage img;
PImage img_r, img_g, img_b;
int[] hist_r = new int[256];
int[] hist_g = new int[256];
int[] hist_b = new int[256];
int histMax;
void setup()
{
size(640, 480);
img = loadImage("C:/Users/tomoh/OneDrive/Pictures/Drone.jpg");
img_r = createImage(img.width, img.height, RGB);
img_g = createImage(img.width, img.height, RGB);
img_b = createImage(img.width, img.height, RGB);
int sz = img.width * img.height;
for (int loc = 0; loc < sz; loc++) {
int r = (int)red(img.pixels[loc]);
int g = (int)green(img.pixels[loc]);
int b = (int)blue(img.pixels[loc]);
img_r.pixels[loc] = color(r, 0, 0); hist_r[r]++;
img_g.pixels[loc] = color(0, g, 0); hist_g[g]++;
img_b.pixels[loc] = color(0, 0, b); hist_b[b]++;
}
histMax = max(max(hist_r), max(hist_g), max(hist_b));
}
void draw()
{
int w = img.width / 3, h = img.height / 3;
image(img, w, 0, w, h);
image(img_r, 0, h, w, h);
image(img_g, w, h, w, h);
image(img_b, 2*w, h, w, h);
int y, b = (int)(img.height * 0.95);
for (int i = 0; i < 256; i++) {
int j = (int)map(i, 0, 256, 0, w);
y = (int)map(hist_r[j], 0, histMax, 0, h);
stroke(255, 255, 255, 128); line(j, b, j , b - y);
y = (int)map(hist_g[j], 0, histMax, 0, h);
stroke(255, 255, 0, 128); line(w + j, b, w + j , b - y);
y = (int)map(hist_b[j], 0, histMax, 0, h);
stroke(0, 255, 255, 128); line(2*w + j, b, 2*w + j , b - y);
}
}
[/code]
このプログラムは、画像を 1枚しか読み込んでいないので、
2枚読み込むようにしたもの提示してください。