Example #1
0
void RangeScanner::depth_image(SparseRangeScan* _scan, string _filename)  {
	double** r_scan = new double*[sensor.resy()];
	double** g_scan = new double*[sensor.resy()];
	double** b_scan = new double*[sensor.resy()];
	for(int y = 0; y < sensor.resy(); y++)  {
		r_scan[y] = new double[sensor.resx()];
		g_scan[y] = new double[sensor.resx()];
		b_scan[y] = new double[sensor.resx()];
		for(int x = 0; x < sensor.resx(); x++)  {
			r_scan[y][x] = 0;
			g_scan[y][x] = 0;
			b_scan[y][x] = 0;
		}
	}

	double min_depth = 1e10, max_depth = -1e10;
	for(int p = 0; p < _scan->size(); p++)  {
		PixelCoord pix = _scan->getPixel(p);
		Vector3 pt = _scan->getPt(p);
		double depth = pt.length(sensor.camera_pos());
		min_depth = depth < min_depth ? depth : min_depth;
		max_depth = depth > max_depth ? depth : max_depth;
	}
	for(int p = 0; p < _scan->size(); p++)  {
		PixelCoord pix = _scan->getPixel(p);
		Vector3 pt = _scan->getPt(p);
		double depth = pt.length(sensor.camera_pos());
		double normalized_depth = 1.0 - ((depth-min_depth) / (max_depth-min_depth));
		r_scan[pix.y][pix.x] = normalized_depth;
		g_scan[pix.y][pix.x] = normalized_depth;
		b_scan[pix.y][pix.x] = normalized_depth;
	}

	PNGImage png_image(_filename, sensor.resx(), sensor.resy());
	for(int y = 0; y < sensor.resy(); y++)  {
		for(int x = 0; x < sensor.resx(); x++)  {
			double r = r_scan[y][x], g = g_scan[y][x], b = b_scan[y][x];
			png_image.set_png_pixel(x,(sensor.resy()-y)-1, r, g, b);
		}
	}
	png_image.write_to_file();

	for(int y = 0; y < sensor.resy(); y++)  {
		delete [] r_scan[y];
		delete [] g_scan[y];
		delete [] b_scan[y];
	}
	delete [] r_scan;
	delete [] g_scan;
	delete [] b_scan;
}
Example #2
0
void RangeSubset::write_to_file(string _filename, double** _r, double** _g, double** _b)  {
	if(contains_nothing)
		return;

	PNGImage png_image(_filename, res_x, res_y);
	for(int y = 0; y < res_y; y++)  {
		for(int x = 0; x < res_x; x++)  {
			double r = _r[y][x], g = _g[y][x], b = _b[y][x];
			if(x >= start_x && x <= end_x)  {
				double intensity = intensities[y][x-start_x];
				r = 1.0*intensity + r*(1.0-intensity);
				g = 0.0*intensity + g*(1.0-intensity);
				b = 0.0*intensity + b*(1.0-intensity);
			}
			png_image.set_png_pixel(x,(res_y-y)-1, r, g, b);
		}
	}
	png_image.write_to_file();
}
Example #3
0
File: plot_png.cpp Project: ycool/c
void save_image_to_file(const std::string file) {
	int num_rows = 600;
	int num_columns = 600;
    cv::Mat png_image(num_rows, num_columns, CV_8UC3);
    for (int x = 0; x < num_rows; ++x) {
        for (int y = 0; y < num_columns; ++y) {
            cv::Vec3b& color = png_image.at<cv::Vec3b>(x, y);
            if (x == y) {
                color = cv::Vec3b(0, 0, 255); // blue-green-red
            } else if (x == 0 || y == 0 || x == num_rows -10 || y == num_columns - 10) {
                color = cv::Vec3b(0, 255, 0);            	
            }
            else {
                color = cv::Vec3b(0, 0, 0);
            }
        }
    }
    std::vector<int> compression_params;
    compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
    compression_params.push_back(3);

    cv::imwrite(file, png_image, compression_params);
}
Example #4
0
void RangeScanner::ray_tracer(string _filename)  {
	ImplicitNewton* implicit_solver = (lipschitz == 0) ? new ImplicitNewton(shape, 1.0, 1e-7) : new ImplicitNewton(shape, 1.0, 1e-7, lipschitz);
	double my_pi = acos(-1);

	int total_res = sensor.resx()*sensor.resy();
	int fraction = total_res/10;
	int ind = 0;
	int num_hits = 0, num_valid_hits = 0;

	Vector3 ray_pos, ray_dir;
	double t_hit;

	double** r_scan = new double*[sensor.resy()];
	double** g_scan = new double*[sensor.resy()];
	double** b_scan = new double*[sensor.resy()];
	for(int y = 0; y < sensor.resy(); y++)  {
		r_scan[y] = new double[sensor.resx()];
		g_scan[y] = new double[sensor.resx()];
		b_scan[y] = new double[sensor.resx()];
		for(int x = 0; x < sensor.resx(); x++)  {
			r_scan[y][x] = 1;
			g_scan[y][x] = 1;
			b_scan[y][x] = 1;
		}
	}

	for(int y = 0; y < sensor.resy(); y++)  {
		for(int x = 0; x < sensor.resx(); x++)  {
			ind++;

			if((ind % fraction) == 0)
				cout << ((double)ind / (double)total_res) << " done with range image... " << num_valid_hits << " / " << num_hits << endl;

			sensor.generatePerspectiveRay(x, y, ray_pos, ray_dir);
			if(implicit_solver->intersection(ray_pos, ray_dir, t_hit))  {
				num_hits++;
				Vector3 range_pt = ray_pos + ray_dir*t_hit;
				Vector3 range_normal = shape->normal(range_pt);

				num_valid_hits++;

				Vector3 light_vec = sensor.camera_pos()-range_pt;
				light_vec.normalize();
				double dot = fabs(light_vec.dotProduct(range_normal));
				r_scan[y][x] = (236.0/255.0)*dot;
				g_scan[y][x] = (211.0/255.0)*dot;
				b_scan[y][x] = (143.0/255.0)*dot;
			}
		}
	}

	PNGImage png_image(_filename, sensor.resx(), sensor.resy());
	for(int y = 0; y < sensor.resy(); y++)  {
		for(int x = 0; x < sensor.resx(); x++)  {
			double r = r_scan[y][x], g = g_scan[y][x], b = b_scan[y][x];
			png_image.set_png_pixel(x,(sensor.resy()-y)-1, r, g, b);
		}
	}
	png_image.write_to_file();

	for(int y = 0; y < sensor.resy(); y++)  {
		delete [] r_scan[y];
		delete [] g_scan[y];
		delete [] b_scan[y];
	}
	delete [] r_scan;
	delete [] g_scan;
	delete [] b_scan;

	delete implicit_solver;
}