ThreeB 1.1
|
00001 00002 /** Scales an image in to the correct range for bytes. 00003 @param hi Brightest pixel in the image 00004 @param lo Dimmest pixel in the image 00005 @param im Image to scale 00006 @returns scaled image 00007 @ingroup gDebug 00008 */ 00009 Image<byte> scale_to_bytes(const Image<float>& im, float lo, float hi) 00010 { 00011 Image<byte> out(im.size()); 00012 for(int r=0; r < out.size().y-0; r++) 00013 for(int c=0; c < out.size().x-0; c++) 00014 out[r][c] = (int)floor((im[r][c]-lo)*255/(hi-lo)); 00015 00016 return out; 00017 } 00018 00019 /** Find the variance of every patch in the image and save it to a file 00020 @ingroup gDebug 00021 @param ims List of images. 00022 */ 00023 void test_output_patch_variance(const vector<Image<float> >& ims) 00024 { 00025 assert_same_size(ims); 00026 00027 int rr = GV3::get<int>("test.variance.radius", 1, -1); 00028 ImageRef r(rr, rr); 00029 ImageRef size = r*2 + ImageRef(1,1); 00030 00031 Image<float> stds(ims.front().size(), 0); 00032 00033 ImageRef p; 00034 for(ImageRef p(0,0); p.y < stds.size().y - size.y; p.y++) 00035 { 00036 for(p.x=0; p.x < stds.size().x - size.x; p.x++) 00037 stds[p + r] = sqrt(mean_and_variance(sub_images(ims, p, size)).second); 00038 } 00039 00040 SubImage<float> s = stds.sub_image(ImageRef(2,2), stds.size() - ImageRef(4,4)); 00041 00042 float hi = *max_element(s.begin(), s.end()); 00043 float lo = *min_element(s.begin(), s.end()); 00044 cerr << hi << " " << lo << endl; 00045 img_save(scale_to_bytes(stds, lo, hi), "test_variance.png"); 00046 } 00047 00048 00049 00050 00051