「小さなフィルタのサンプル5」の編集履歴(バックアップ)一覧に戻る
public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) { pictFilter2 PF = new pictFilter2(100d, pictureBox1); Bitmap b2 = new Bitmap(pictureBox1.Image); PF.Add_Color_frequency_table(b2); } }
public class pictFilter2 { cell_date[, ,] Cells; PictureBox outPictureBox; double cell_size; Bitmap b2; Bitmap outBit;
public pictFilter2(double cell_size1,PictureBox p1) { int areaCount=(int)Math.Floor(510 / cell_size1) + 3; outPictureBox = p1; Cells = new cell_date[areaCount, areaCount, areaCount]; for (int i = 0; i < areaCount; i++) { for (int j = 0; j < areaCount; j++) { for (int k = 0; k < areaCount; k++) { Cells[i, j, k] = new cell_date(); } } }
this.cell_size = cell_size1; }
public void Add_Color_frequency_table(Bitmap b1) { Color CD, CR, CC;//CCが今の升目で後は下、右 for (int i = 0; i < b1.Width-1; i++) { for (int j = 0; j < b1.Height-1; j++) { //イラストフィルタなので数学的厳密さは求めずに適当にデータを取ってます CC = b1.GetPixel(i, j); CD = b1.GetPixel(i, j + 1); CR = b1.GetPixel(i + 1, j); addCellDate(CC, CD); addCellDate(CC, CR);
} } int hh;
} public void set_Pict(Bitmap inBit) { b2 = inBit; outBit = null; }
public void addCellDate(Color C1, Color C2) { int r,g,b; r = C1.R - C2.R; g = C1.G - C2.G; b = C1.B - C2.B; this.Cells[getCell_Point(r) ,getCell_Point(g),getCell_Point(b)].add(r,g,b); } public int getCell_Point(int rgb) { return (int)Math.Floor((rgb + 255) /this.cell_size ) + 1; }
public void sand_moveFilter1() { //差分空間の近傍から一番頻度の大きい差分に近づける処理
} public void sand_miveFilter2() { //差分空間の近傍から最頻値を平均的な確立で取ってくる処理 } public void sand_miveFilter3() { //差分空間の近傍から最頻値を取り更に上下左右のマスとの平均を足す } public void sand_miveFilter4() { //砂山遊びにヒントを得た処理 2枚の絵の差分を移動して近づける処理 //言うは安し具体的な操作に落とすは難しい }
} public class cell_date { int sumR =0; int sumG =0; int sumB =0; int count=0;
public void add(int r, int g, int b) { count++; sumR += r; sumG += g; sumB += b; } public void add(Color C){ count++; sumR += C.R; sumG += C.G; sumB += C.B;
} public Color aveColor() { if (count > 0) { return Color.FromArgb((int)sumR / count, (int)sumG / count, (int)sumB / count); }else{ return Color.FromArgb(sumR,sumG ,sumB); } } }