示例#1
0
char runNetwork(Magick::Image& image) {
    resetNetwork();
    for (int i = 0; i < xsize; i++) {
        for (int j = 0; j < ysize; j++) {
            Magick::ColorGray color = image.pixelColor(i, j);
            inputs[xsize * i + j]->setState(color.shade() * 2 - 1);
        }
    }
        for (int i = 0; i < hidden_layers_count; i++) {
            Thread_pool pool;
            for (int j = 0; j < hidden_layers_size; j++) {
                //std::cerr << i << "-" << j << std::endl;
                pool.submit(std::bind(&Neuron::calcEnergy, hidden_layers[i][j]));
            }
        }
    {
        Thread_pool pool;
        for (int i = 0; i < outputs.size(); i++) {
            pool.submit(std::bind(&NetworkOutput::calcEnergy, outputs[i]));
        }
    }

    int maxi = 0;
    for (int i = 0; i < outputs.size(); i++) {
        if (outputs[i]->getSignal() > outputs[maxi]->getSignal()) 
            maxi = i;
    }
    return maxi + 'a';
}
示例#2
0
void VoxelGrid::
paintHeightMap(const GridDescription & gridDesc,
	const HeightMap & instruction)
{
	Rect3i yeeRect = instruction.yeeRect();
	Vector3i u1 = instruction.rowDirection();
	Vector3i u2 = -instruction.columnDirection();
	Vector3i u3 = instruction.upDirection();
	
	int nUp = abs(dot(u3, yeeRect.p2-yeeRect.p1)) + 1;
	
	Mat3i matrixImgToGrid(Mat3i::withColumns(u1,u2,u3));
	
	// this will select the correct corner of the fill rect regardless of the
	// direction of the image unit vectors.  This point corresponds to the
	// origin of the image (top-left pixel of the .bmp or .*).
	Vector3i fillOrigin = clip(yeeRect,
		Vector3i(-100000*u1 + -100000*u2 + -100000*u3) );
	
	// now the image!
	Magick::Image heightMap;
	try {
		heightMap.read(instruction.imageFileName());
		FillStyle style = instruction.fillStyle();
		Paint* paint = Paint::paint(instruction.material());
		
		// iterate over rows and columns of the image; extrude into grid
		for (unsigned int row = 0; row < heightMap.rows(); row++)
		for (unsigned int col = 0; col < heightMap.columns(); col++)
		{
			Magick::ColorGray color = heightMap.pixelColor(col, row);
			int height = int(double(nUp)*color.shade());
			
			Vector3i p = fillOrigin + matrixImgToGrid*Vector3i(col, row, 0);
			for (int up = 0; up < height; up++)
			{
				Vector3i pGrid = p + u3*up;
				if (style == kPECStyle)
					paintPEC(paint, pGrid[0], pGrid[1], pGrid[2]);
				else if (style == kPMCStyle)
					paintPMC(paint, pGrid[0], pGrid[1], pGrid[2]);
                else
                    paintYeeCell(paint, pGrid[0], pGrid[1], pGrid[2]);
			}
		}
	} catch (Magick::Exception & magExc) {
		cerr << "Error reading HeightMap.  Maybe a file type issue?\n";
		cerr << "Caught ImageMagick exception " << magExc.what() << endl;
		LOG << "Exception logged.  Exiting.\n";
		exit(1);
	}
}
示例#3
0
Preprocessor::Preprocessor (const Magick::Image& page, const unsigned int& x, const unsigned int& y, const unsigned int& height, const unsigned int& width)
:	clip_(0),
	clipHeight_(height),
	clipWidth_(width),
	statistics_(),
	regions_(0),
	delimiters_(0),
	inlineRegions_(),
	patterns_(0),
	averageCharacterHeight_(0.0),
	averageCharacterWidth_(0.0),
	averageSpaceBetweenCharacters_(0.0)
{
	if ( (height == 0) && (width == 0) )
		throw NessieException ("Preprocessor::Preprocessor() : Constructor has 0 size.");

	if ( width > page.columns() )
		throw NessieException ("Preprocessor::Preprocessor() : The press clip's width cannot be wider than the underlying page's.");

	if ( height > page.rows() )
		throw NessieException ("Preprocessor::Preprocessor() : The press clip's height cannot be higher than the underlying page's.");

	if ( x >= page.rows() || y >= page.columns() )
		throw NessieException ("Preprocessor::Preprocessor() : The press clip's top leftmost pixel falls outside the page.");

	if( (x + height) > page.rows() || (y + width) > page.columns() )
		throw NessieException ("Preprocessor::Preprocessor() : The clip does not fall completely within the underlying page.");

	// Create a view over the input image
	Magick::Pixels imageView(const_cast<Magick::Image&>(page));
	Magick::PixelPacket *pixels = imageView.get(x, y, clipWidth_, clipHeight_);

	// Traverse the view to get the pixel values
	Magick::ColorGray grayLevel;
	for ( unsigned int i = 0; i < clipHeight_; ++i )
	{
		for ( unsigned int j = 0; j < clipWidth_; ++j )
		{
			grayLevel = *pixels++;
			clip_.push_back( static_cast<unsigned char>(round(grayLevel.shade() * 255.0)) );
		}
	}

	statistics_.clipSize(clip_.size());
}