コード例 #1
0
SceneImage::SceneImage(SceneGLWindow *window)
    : AbstractGLScene(window)
{
    initializeImage();
    m_tex = QImage(":/images/crate.jpg");
    m_texture = nullptr;
}
コード例 #2
0
ファイル: Image.cpp プロジェクト: roteroktober/stromx-studio
void Image::initializeParent()
{
    stromx::runtime::Image::PixelType pixelType = stromx::runtime::Image::MONO_8;
    
    switch(m_image.format())
    {
    case QImage::Format_Indexed8:
        pixelType = stromx::runtime::Image::MONO_8;
        break;
    case QImage::Format_RGB888:
        pixelType = stromx::runtime::Image::RGB_24;
        break;
    default:
        m_image = QImage();
    }
    
    setBuffer(reinterpret_cast<uint8_t*>(m_image.bits()), m_image.byteCount());
    
    initializeImage(m_image.width(), m_image.height(), m_image.bytesPerLine(),
                    m_image.bits(), pixelType);
}
コード例 #3
0
ファイル: imagearea.cpp プロジェクト: edo248/EasyPaint
ImageArea::ImageArea(const bool &isOpen, const QString &filePath, QWidget *parent) :
    QWidget(parent), mIsEdited(false), mIsPaint(false), mIsResize(false)
{
    setMouseTracking(true);

    mRightButtonPressed = false;
    mFilePath.clear();
    makeFormatsFilters();
    initializeImage();
    mZoomFactor = 1;

    mAdditionalTools = new AdditionalTools(this);

    mUndoStack = new QUndoStack(this);
    mUndoStack->setUndoLimit(DataSingleton::Instance()->getHistoryDepth());

    if(isOpen && filePath.isEmpty())
    {
        open();
    }
    else if(isOpen && !filePath.isEmpty())
    {
        open(filePath);
    }
    else
    {
        QPainter *painter = new QPainter(mImage);
        painter->fillRect(0, 0,
                          DataSingleton::Instance()->getBaseSize().width(),
                          DataSingleton::Instance()->getBaseSize().height(),
                          Qt::white);
        painter->end();

        resize(mImage->rect().right() + 6,
               mImage->rect().bottom() + 6);
    }

    QTimer *autoSaveTimer = new QTimer(this);
    autoSaveTimer->setInterval(DataSingleton::Instance()->getAutoSaveInterval() * 1000);
    connect(autoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSave()));
    connect(mAdditionalTools, SIGNAL(sendNewImageSize(QSize)), this, SIGNAL(sendNewImageSize(QSize)));

    autoSaveTimer->start();

    SelectionInstrument *selectionInstrument = new SelectionInstrument(this);
    connect(selectionInstrument, SIGNAL(sendEnableCopyCutActions(bool)), this, SIGNAL(sendEnableCopyCutActions(bool)));
    connect(selectionInstrument, SIGNAL(sendEnableSelectionInstrument(bool)), this, SIGNAL(sendEnableSelectionInstrument(bool)));

    // Instruments handlers
    mInstrumentsHandlers.fill(0, (int)INSTRUMENTS_COUNT);
    mInstrumentsHandlers[CURSOR] = selectionInstrument;
    mInstrumentsHandlers[PEN] = new PencilInstrument(this);
    mInstrumentsHandlers[LINE] = new LineInstrument(this);
    mInstrumentsHandlers[ERASER] = new EraserInstrument(this);
    mInstrumentsHandlers[RECTANGLE] = new RectangleInstrument(this);
    mInstrumentsHandlers[ELLIPSE] = new EllipseInstrument(this);
    mInstrumentsHandlers[FILL] = new FillInstrument(this);
    mInstrumentsHandlers[SPRAY] = new SprayInstrument(this);
    mInstrumentsHandlers[MAGNIFIER] = new MagnifierInstrument(this);
    mInstrumentsHandlers[COLORPICKER] = new ColorpickerInstrument(this);
    mInstrumentsHandlers[CURVELINE] = new CurveLineInstrument(this);
    mInstrumentsHandlers[TEXT] = new TextInstrument(this);

    // Effects handlers
    mEffectsHandlers.fill(0, (int)EFFECTS_COUNT);
    mEffectsHandlers[NEGATIVE] = new NegativeEffect(this);
    mEffectsHandlers[GRAY] = new GrayEffect(this);
    mEffectsHandlers[BINARIZATION] = new BinarizationEffect(this);
    mEffectsHandlers[GAUSSIANBLUR] = new GaussianBlurEffect(this);
    mEffectsHandlers[GAMMA] = new GammaEffect(this);
    mEffectsHandlers[SHARPEN] = new SharpenEffect(this);
    mEffectsHandlers[CUSTOM] = new CustomEffect(this);
}
void OpenCVDisplay::resize( int width, int height ) throw(DisplayException) {
	BaseDisplay::resize(width,height);
	initializeImage(width,height);
}
OpenCVDisplay::OpenCVDisplay(int w, int h) throw(DisplayException) : image(NULL) {
	initializeImage(w,h);
}
コード例 #6
0
ファイル: Classifier.cpp プロジェクト: waynegerard/cell-scope
	cv::Mat runWithImage(const cv::Mat image)
	{
        cout << "Running with image\n";
		if(!image.data) {
            cout << "Image has no data! Returning.\n";
			return cv::Mat::zeros(1,1,CV_8UC1);
		}

		cv::Mat normalizedImage = initializeImage(image);
		cv::Mat imageBw = objectIdentification(normalizedImage);
		//Debug::print(imageBw, "imbw.txt");
		//cv::Mat imageBw = Debug::loadMatrix("imbw.txt", normalizedImage.rows, normalizedImage.cols, CV_8UC1);

		// Feature detection
		vector<MatDict > features = featureDetection(imageBw, normalizedImage);
		
        Debug::printFeatures(features, "phi");
		Debug::printFeatures(features, "origPatch");
		Debug::printFeatures(features, "binPatch");
		Debug::printFeatures(features, "geom");

        // Classify Objects
        vector<double> prob_results = classifyObjects(features);

        // Sort scores, keeping index
        vector<pair<double, int> > prob_results_with_index;
        vector<double>::iterator it = prob_results.begin();
        int index = 0;
        for (; it != prob_results.end(); it++)
        {
            prob_results_with_index.push_back(make_pair(*it, index));
            index++;
        }
        
        sort(prob_results_with_index.begin(), prob_results_with_index.end(), comparator);
        Debug::printPairVector(prob_results_with_index, "dvtest_sorted.txt");

		int too_low = 0;
		index = 0;
		cv::Mat scores_and_centers;
		vector<pair<double, int> >::const_iterator pit = prob_results_with_index.begin();

		float max_distance = pow(pow(normalizedImage.rows, 2.0) + pow(normalizedImage.cols, 2.0), 0.5);
		for (; pit != prob_results_with_index.end(); pit++) {
			pair<double, int> score_with_index = *pit;
			double score = score_with_index.first;
			int score_index = score_with_index.second;

			if (score > 1E-6) {
				MatDict feature = features[score_index];
				cv::Mat rowMat = feature.find("row")->second;
				cv::Mat colMat = feature.find("col")->second;
				int row = (int) rowMat.at<float>(0, 0);
				int col = (int) colMat.at<float>(0, 0);

				float min_distance = max_distance;
				int min_index = 0;
				int counter = 0;

				vector<MatDict >::const_iterator fit = features.begin();
				for (; fit != features.end(); fit++) {
					MatDict other_feature = *fit;
					
					cv::Mat other_row_mat = other_feature.find("row")->second;
					cv::Mat other_col_mat = other_feature.find("col")->second;
					int other_row = (int) other_row_mat.at<float>(0, 0);
					int other_col = (int) other_col_mat.at<float>(0, 0);

					if (other_row != row || other_col != col) {
						float distance = pow(pow(row - other_row, 2.0) + pow(col - other_col, 2.0), 0.5);
						if (distance < min_distance) {
							min_distance = distance;
							min_index = counter;
						}
					}
					counter++;
				}

				float too_close = 0.75 * PATCH_SIZE;
				if (min_distance <= too_close) {
					MatDict feature = features[min_index];
					cv::Mat close_feature_row = feature.find("row")->second;
					cv::Mat close_feature_col = feature.find("col")->second;
					close_feature_row.at<float>(0, 0) = -1 * normalizedImage.rows;
					close_feature_col.at<float>(0, 0) = -1 * normalizedImage.cols;
					feature.insert(std::pair<const char*, cv::Mat>("row", close_feature_row));
					feature.insert(std::pair<const char*, cv::Mat>("col", close_feature_col));
					features[min_index] = feature;
					too_close++;
				} else {
					scores_and_centers.create(index + 1, 3, CV_32F);
					scores_and_centers.at<float>(index, 0) = (float) score;
					scores_and_centers.at<float>(index, 1) = (float) row;
					scores_and_centers.at<float>(index, 2) = (float) col;
				}
			} else {
				too_low++;
			}
			index++;
		} 
        
		return scores_and_centers;
	}
コード例 #7
0
/*
 * NewImage - create a new image and return the image type (bitmap, icon, or cursor)
 */
int NewImage( int img_type, const char *filename )
{
    WPI_DLGPROC         dlgproc;
    INT_PTR             button_type;
    short               width;
    short               height;
    short               bcount;
    img_node            node;
    char                ext[_MAX_EXT];

    // If filename is not NULL and we don't know the image type,
    // then guess based on the file extesion.
    if( filename != NULL && img_type == UNDEF_IMG ) {
        _splitpath( filename, NULL, NULL, NULL, ext );
        if( stricmp( ext, ".bmp" ) == 0 ) {
            img_type = BITMAP_IMG;
        } else if( stricmp( ext, ".ico" ) == 0 ) {
            img_type = ICON_IMG;
        } else if( stricmp( ext, ".cur" ) == 0 ) {
            img_type = CURSOR_IMG;
        }
    }

    if( img_type == UNDEF_IMG ) {
        dlgproc = _wpi_makedlgprocinstance( SelImgDlgProc, Instance );
        button_type = _wpi_dialogbox( HMainWindow, dlgproc, Instance, SELECTIMAGE, 0L );
        _wpi_freedlgprocinstance( dlgproc );

        if( button_type == DLGID_CANCEL ) {
            return( FALSE );
        }
    } else {
        imgType = img_type;
    }

    imageCount++;

    switch( imgType ) {
    case BITMAP_IMG:
        dlgproc = _wpi_makedlgprocinstance( SelBitmapDlgProc, Instance );
        button_type = _wpi_dialogbox( HMainWindow, dlgproc, Instance, BITMAPTYPE, 0L );
        _wpi_freedlgprocinstance( dlgproc );
        if( button_type == DLGID_CANCEL ) {
            imgType = UNDEF_IMG;
            imageCount--;
            return( imgType );
        } else if( button_type == SEL_SELECT ) {
#ifdef __OS2_PM__
            IEDisplayErrorMsg( WIE_NOTE, WIE_NOTIMPLEMENTED, MB_OK | MB_ICONINFORMATION );
            return( FALSE );
#else
            if( !SelectDynamicBitmap( &node, imageCount, filename ) ) {
                return( FALSE );
            }
#endif
        } else {
            initializeImage( &node, filename );
        }
        break;

    case ICON_IMG:
        if( !CreateNewIcon( &width, &height, &bcount, TRUE ) ) {
            imgType = UNDEF_IMG;
            return( imgType );
        }
        imgWidth = width;
        imgHeight = height;
        bitCount = bcount;
        initializeImage( &node, filename );
        break;

    case CURSOR_IMG:
#ifdef __OS2_PM__
        if( !CreateNewIcon( &width, &height, &bcount, FALSE ) ) {
            imgType = UNDEF_IMG;
            return( imgType );
        }
        imgWidth = width;
        imgHeight = height;
        bitCount = bcount;
#else
        dlgproc = MakeProcInstance_DLG( SelCursorDlgProc, Instance );
        button_type = JDialogBox( Instance, "CURSORTYPE", HMainWindow, dlgproc );
        FreeProcInstance_DLG( dlgproc );
        if( button_type == IDCANCEL ) {
            imgType = UNDEF_IMG;
            return( imgType );
        }
#endif
        initializeImage( &node, filename );
        break;

    default:
        return( FALSE );
    }

    node.wrinfo = NULL;
    node.lnode = NULL;

    CreateNewDrawPad( &node );

    SetupMenuAfterOpen();

    return( imgType );

} /* NewImage */
コード例 #8
0
ファイル: drawing.cpp プロジェクト: abrock/Embroidermodder
 void initializeImage(EmbPattern* p, const struct EmbStitchList_ * stop = 0) {
     initializeImage(p->stitchList, stop);
 }
コード例 #9
0
ファイル: raytrace.cpp プロジェクト: zcross/simple-raytracer
int main(int argc, char** argv)
{
	printf("Initializing image.\n");
	initializeImage(512, 512);
	printf("Configuring scene.\n");
    Scene scene = configureScene();
    printf("Loading camera.\n");
    Camera eye = *scene.getCamera();

    printf("Beginning render.\n");

    /* Status message: indicate rendering mode. */
    #ifdef _TRACE_MODE_INT_ONLY_
	printf("Rendering in intersection-only mode.\n");
	#elif defined(_TRACE_MODE_NO_AA_)
	printf("Rendering in shading-only mode (No AA).\n");
	#else
	printf("Rendering in full mode (Shading + AA).\n");
	printf("Using %d samples for antialiasing.\n", N_SAMPLES);
	#endif

	/************ Reduced functionality modes (part a & b) *************/
	#if defined(_TRACE_MODE_INT_ONLY_) || defined(_TRACE_MODE_NO_AA_)

	int percentile = 0;
	for(int iy = 0; iy < ny; iy++){
		for(int ix = 0; ix < nx; ix++){
			Ray ray = eye.getRay(ix, iy);
			Intersection* hit = scene.intersect(ray, 0.0, HUGE);
			if(hit)
				#if defined(_TRACE_MODE_INT_ONLY_)
				colorPixel(image, ix, iy, Color(1.0f, 1.0f, 1.0f), 1.0f, nx, ny);
				#else
				colorPixel(image, ix, iy, scene.shade(ray, *hit, BACKGROUND), 2.2f, nx, ny);
				#endif
		}

		/* Rough estimate of percent progress. */
		if((1.0 * iy)/(ny-1) >= 0.10*percentile && percentile <= 10){
			printf("%d%%\n", percentile++ * 10);
		}
	}

	#else
	/********** Shading and anti-aliasing. (Default) (part c) ***********/

	int percentile = 0;
	int one_dim_steps = sqrt(N_SAMPLES);
	float stepsize = 1.0f/one_dim_steps;

	for(int iy = 0; iy < ny; iy++){
		for(int ix = 0; ix < nx; ix++){
			Color sampleSum = BACKGROUND;

			/* Stratified sampling within pixel, with additional random jitter. */
			for(int sy = 0; sy < one_dim_steps; sy++){
				for(int sx = 0; sx < one_dim_steps; sx++){
					float x, y, jx, jy;

					// Generate random jitter in [0, 1.0]
					jx = (float)rand()/(float)RAND_MAX;
					jy = (float)rand()/(float)RAND_MAX;

					// Work with a fixed stepsize, but add additional random factor in [0, 1.0] (s_ + j_)
					x = ix - 0.5f + (sx + jx) * stepsize; // -0.5 moves from center point to left boundary
					y = iy - 0.5f + (sy + jy) * stepsize; // -0.5 moves from center point to top boundary
					
					// Generate eye ray from the stratified/random position within pixel
					Ray r = eye.getRay(x, y);

					// Add to sum of sampled colors on hit, with baseline value equal to BACKGROUND
					Intersection *hit = scene.intersect(r, 0.0f, HUGE);
					if(hit)
						sampleSum += scene.shade(r, *hit, BACKGROUND);
				}
			}
			// Finally, color the pixel at (ix, iy) by the average sampled color, with gamma correction.
			colorPixel(image, ix, iy, sampleSum * (1.0f / (one_dim_steps*one_dim_steps)), 2.2f, nx, ny);
		}

		/* Rough estimate of percent progress. */
		if((1.0 * iy)/(ny-1) >= 0.10*percentile && percentile <= 10){
			printf("%d%%\n", percentile++ * 10);
		}
	}
	#endif

	// Configure GLUT for rendering via OpenGL
	setup_glut(argc, argv);
	return EXIT_SUCCESS;
	
}
コード例 #10
0
ファイル: imagearea.cpp プロジェクト: 13vv2/praktika
ImageArea::ImageArea(const bool &isOpen, const QString &filePath, QWidget *parent) :
    QWidget(parent), mIsEdited(false), mIsPaint(false), mIsResize(false)
{
    setMouseTracking(true);

    mRightButtonPressed = false;
    mFilePath = QString();
    mOpenFilter = "Windows Bitmap(*.bmp)";
    mSaveFilter = "Windows Bitmap(*.bmp)";
    initializeImage();
    mZoomFactor = 1;

    mAdditionalTools = new AdditionalTools(this, this->parent());

    if(isOpen && filePath.isEmpty())
    {
        open();
    }
    else if(isOpen && !filePath.isEmpty())
    {
        open(filePath);
    }
    else
    {
        int width, height;
        width = Data::Instance()->getBaseSize().width();
        height = Data::Instance()->getBaseSize().height();
        if (Data::Instance()->getIsInitialized() &&
            Data::Instance()->getIsAskCanvasSize())
        {
            QClipboard *globalClipboard = QApplication::clipboard();
            QImage mClipboardImage = globalClipboard->image();
            if (!mClipboardImage.isNull())
            {
                width = mClipboardImage.width();
                height = mClipboardImage.height();
            }
            mAdditionalTools->resizeCanvas(width, height);
            mIsEdited = false;
        }
        QPainter *painter = new QPainter(mImage);
        painter->fillRect(0, 0, width, height, Qt::white);
        painter->end();

        resize(mImage->rect().right() + 6,
               mImage->rect().bottom() + 6);
        mFilePath = QString("");
    }

    SelectionInstrument *selectionInstrument = new SelectionInstrument(this);
    connect(selectionInstrument, SIGNAL(sendEnableCopyCutActions(bool)), this, SIGNAL(sendEnableCopyCutActions(bool)));
    connect(selectionInstrument, SIGNAL(sendEnableSelectionInstrument(bool)), this, SIGNAL(sendEnableSelectionInstrument(bool)));

    mInstrumentsHandlers.fill(0, (int)INSTRUMENTS_COUNT);
    mInstrumentsHandlers[CURSOR] = selectionInstrument;
    mInstrumentsHandlers[PEN] = new PencilInstrument(this);
    mInstrumentsHandlers[LINE] = new LineInstrument(this);
    mInstrumentsHandlers[ERASER] = new EraserInstrument(this);
    mInstrumentsHandlers[RECTANGLE] = new RectangleInstrument(this);
    mInstrumentsHandlers[ELLIPSE] = new EllipseInstrument(this);
    mInstrumentsHandlers[FILL] = new FillInstrument(this);
    mInstrumentsHandlers[CURVELINE] = new CurveLineInstrument(this);
}