2013/08/18(Sun) 14:27:30 編集(投稿者)
> ttp://ohta-lab.jp/users/mitsugu/research/VSSS/main.html
ココ↑にあった"絵"を頼りにエイヤで書いてみた。
#include <iostream>
#include <valarray>
#include <random>
using namespace std;
void print(valarray<bool> ary, int width) {
for ( size_t i = 0; i < ary.size(); ++i ) {
cout << (ary[i] ? '#' : ' ');
if ( (i+1) % width == 0 ) cout << endl;
}
}
int main() {
const int WIDTH = 30;
const int HEIGHT = 15;
bool s[HEIGHT][WIDTH]={
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0,
0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
valarray<bool> src(HEIGHT*WIDTH);
for ( size_t i = 0; i < src.size(); ++i ) {
src[i] = (&s[0][0])[i];
}
cout << "--- 元画像 ------------------------------------------\n";
print(src, WIDTH);
valarray<bool> noise(HEIGHT*WIDTH);
mt19937 eng;
bernoulli_distribution toss;
for ( size_t i = 0; i < noise.size(); ++i ) {
noise[i] = toss(eng);
}
cout << "--- ノイズ ------------------------------------------\n";
print(noise, WIDTH);
valarray<bool> imgA(HEIGHT*WIDTH*2);
for ( size_t i = 0; i < noise.size(); ++i ) {
imgA[i*2] = noise[i];
imgA[i*2+1] = !noise[i];
}
cout << "--- 画像A ------------------------------------------\n";
print(imgA, WIDTH*2);
valarray<bool> imgB(HEIGHT*WIDTH*2);
for ( size_t i = 0; i < noise.size(); ++i ) {
imgB[i*2] = (src[i] && !noise[i]) || (!src[i] && noise[i]);
imgB[i*2+1] = !imgB[i*2];
}
cout << "--- 画像B ------------------------------------------\n";
print(imgB, WIDTH*2);
valarray<bool> imgC(HEIGHT*WIDTH*2);
for ( size_t i = 0; i < imgC.size(); ++i ) {
imgC[i] = imgA[i]||imgB[i];
}
cout << "---- 画像 A,B を重ねたもの --------------------------------------\n";
print(imgC, WIDTH*2);
}
/* 実行結果
--- 元画像 ------------------------------------------
# # ##### #######
# # # #
# # # #
# # # #
# # # #
####### # #
# # # #
# # # #
# # # #
# # # #
# # ##### #
--- ノイズ ------------------------------------------
# ## ## # # ###### #### ##
######## # ### ### #
## # #### ## # # #
###### ## ## # ### ###
## #### # ### # ### # #
# # ### # ######## ## ## ##
### ## # # ## ###
# ###### # # ### ## ### # #
## ### ## # ## ## #
## ### #### # # # #
# ## # # ## ##
###### # # # ## # #
## ## ## #### # # # #
# ### #### # ## ## # # ###
# # ## # ## # ###
--- 画像A ------------------------------------------
## # ## # ## ## # ## # # # # # # ## # # # ## # # ##
# # # # # # # # # # # ## # ## # # ## # # ## # # ## # #
# ## # # ## # # # # # ## # # ## # ## # # # ## ## # #
# # # # # # # # # ## # ## # ## ## # # # # ## # # ## #
# ## # # # ## ## # # ## # ## # # # # ## # ## # # ##
# ## ## # # ## ## # # # # # # # # ## # ## # ## # # #
# # # # # # ## # ## # ## # # # ## # # # ## # # # ## #
## # # # # # # # ## ## ## # # ## # ## # # ## # ## #
# # # ## # # # ## # ## # # ## # # ## # ## # ## # # #
# # ## # # ## # # # # ## # # ## # # # ## # # # # ## #
# ## # ## ## # # # ## # ## # # # # # ## # # # # # # #
# # # # # # # ## # # ## # ## # # # ## # ## ## ## # #
# ## # # ## # ## # # # # # # # ## # ## ## # ## # # #
# # ## # # ## # # # ## # ## # ## # ## ## ## # # ##
# ## # # ## # # ## # # # # # # ## # # # # ## ## # # #
--- 画像B ------------------------------------------
## # ## # ## ## # ## # # # # # # ## # # # ## # # ##
# # # # # # # # # # # ## # ## # # ## # # ## # # ## # #
# ## ## ## # # # # # # # ## # ## ## # # ## ## ## #
# # # # # # # # ## # # ## ## # ## # # # # # # # # ## #
# ## # # # ## # # # # ## # # # # # # # ## # # # # # ##
# ## # # # # ## # # # # # ## # # # ## # ## # ## # # #
# # # # # # ## ## # # ## # ## ## # # # ## # # # ## #
## # ## # # # # # # ## ## # # ## # ## # ## # # ## #
# # ## # # # # # # # ## # # # # # # ## # ## # ## # # #
# # # # # # ## # # # # ## # # ## # # # ## # ## # ## #
# ## # ## ## # ## ## # # ## # # # # ## # ## # # # #
# # ## # # # ## ## ## # # ## # # ## # ## # # ## # #
# ## # # ## # # ## # # ## # # # # # ## ## # ## # # #
# # ## # # ## # # # ## # ## # ## # ## ## ## # # ##
# ## # # ## # # ## # # # # # # ## # # # # ## ## # # #
---- 画像 A,B を重ねたもの --------------------------------------
## # ## # ## ## # ## # # # # # # ## # # # ## # # ##
# # # # # # # # # # # ## # ## # # ## # # ## # # ## # #
# ## ### ## # # ## # # ############ ## ############### #
# # # ## # # # # #### # ## #### ## # # # # ### # # ## #
# ## ## # # ## ### # # ## # ### # # # # ## # ### # # ##
# ## ### # # ## ### # # # ### # # # ## # ## ## ## # # #
# # # ## # # ## #### # ## # ### ## # # # ## ## # # ## #
## # ############### ## ## ## # ## # ## # #### # ## #
# # #### # # # ### # ## # # ### # # ## # ## ## ## # # #
# # ### # # ## # ## # # ## # ## ## # # # ## # ### # ## #
# ## ## ## ## # ### ## # #### # # # # ## # ### # # # #
# # ### # # # ## ### ## # #### # # ## # ## ### ## # #
# ## ## # ## # #### # # ########### # ## ## ## ## # # #
# # ## # # ## # # # ## # ## # ## # ## ## ## # # ##
# ## # # ## # # ## # # # # # # ## # # # # ## ## # # #
*/