Beispiel #1
0
static void velvetifySequence(char * str, SequencesWriter *seqWriteInfo) {
	int i;
	char c;
	size_t length = strlen(str);

	for (i = 0; i < length; i++) {
		c = str[i];
		switch (c) {
		case '\n':
		case '\r':
		case EOF:
			str[i] = '\0';
			break;
		case 'A':
		case 'a':
			str[i] = 'A';
			break;
		case 'C':
		case 'c':
			str[i] = 'C';
			break;
		case 'G':
		case 'g':
			str[i] = 'G';
			break;
		case 'T':
		case 't':
			str[i] = 'T';
			break;
		default:
			str[i] = 'N';
		}
		// non NULL indicates ref masks are being created
		if (seqWriteInfo->m_referenceMask != NULL) {
			if (str[i] == 'N') {
				if (seqWriteInfo->m_openMask) {
					seqWriteInfo->m_current->finish++;
				} else if (*(seqWriteInfo->m_referenceMask) == NULL) {
					*(seqWriteInfo->m_referenceMask) = newMask(seqWriteInfo, seqWriteInfo->m_position);
					seqWriteInfo->m_current = *(seqWriteInfo->m_referenceMask);
				} else {
					seqWriteInfo->m_current->next = newMask(seqWriteInfo, seqWriteInfo->m_position);
					seqWriteInfo->m_current = seqWriteInfo->m_current->next;		
				}
				seqWriteInfo->m_openMask = true;
				seqWriteInfo->m_position += 1;
			} else if (str[i] != '\0') {
				seqWriteInfo->m_openMask = false;
				seqWriteInfo->m_position += 1;
			}
		}
	} 
}
Beispiel #2
0
bool MaskedImage::advect(const VectorField2D & velocity, double deltaT,
	UArray<double> & inOutX, UArray<double> & inOutY, double errorTolerance, SInt32 maximumTimeStepCount)
{
	if(deltaT == 0.0)
		return true;
	ParticleIntegrator integrator(velocity);
	double nextTimeStep = 0.1*deltaT;
	double minimumTimeStep = fabs(0.1*deltaT/maximumTimeStepCount);

	SInt32 imageSize = getXSize()*getYSize();
	if(inOutX.getSize() != imageSize || inOutY.getSize() != imageSize)
		return false;

	SInt32 maxCount = 1000000; // keeps us from allocating too much memory at a time

	UArray<double> newData(imageSize);
	UArray<bool> newMask(imageSize);

	for(SInt32 imageIndex = 0; imageIndex < imageSize; imageIndex += maxCount)
	{
		SInt32 localCount = std::min(maxCount, imageSize-imageIndex);
		// set up the points, one for each output pixel
		UArray<double> points(2*localCount);

		for(SInt32 index = 0; index < localCount; index++)
		{
			points[2*index] = inOutX[index + imageIndex];
			points[2*index+1] = inOutY[index + imageIndex];
		}

		// integrate the pixels backward in time to their locations in the original image
		if(!integrator.integrate(points, deltaT, 0, errorTolerance, nextTimeStep, minimumTimeStep, maximumTimeStepCount))
			return false;

		// interpolate the advected image at the points in the original image
		UArray<double> pixelX(localCount), pixelY(localCount), advectedPixels(localCount);
		UArray<bool> advectedMask(localCount);
		for(SInt32 index = 0; index < localCount; index++)
		{
			pixelX[index] = points[2*index];
			pixelY[index] = points[2*index+1];
			inOutX[index + imageIndex] = points[2*index];
			inOutY[index + imageIndex] = points[2*index+1];
		}

		maskedInterpolate(pixelX, pixelY, advectedPixels, advectedMask);

		// copy the advected pixels and mask back into this image
		for(SInt32 index = 0; index < localCount; index++)
		{
			newData[index + imageIndex] = advectedPixels[index];
			newMask[index + imageIndex] = advectedMask[index];
		}
	}
	getData().copy(newData);
	mask.copy(newMask);

	return true;
}
Beispiel #3
0
void MarginCombo::renderImpl(gl::Canvas& canvas, geom::Point const& ptInRoot, geom::Area const& mask)
{
	geom::Area newMask(margin_.apply(mask));
	newMask.point() -= margin_.offset();
	if(auto c = this->frontChild()){
		c->render(
			canvas,
			ptInRoot+this->margin_.offset(),
			newMask
		);
	}
}
Beispiel #4
0
CBlobResult computeWhiteMaskOtsu(Mat& imgRGBin, Mat& imgHSVIn, CBlobResult& blobs, int limitRGB, int limitHSV, double RGBratio, double HSVratio, int bmin, int bmax, int i){
	waitKey(30);
	Mat BGRbands[3];  
	split(imgRGBin,BGRbands);
	Mat imgHSV;
	cvtColor(imgHSVIn,imgHSV,CV_BGR2HSV);
	Mat HSVbands[3];  
	split(imgHSV,HSVbands);
	Mat maskHSV, maskRGB, maskT;

	int otsuTRGB = getThreshVal_Otsu_8u(BGRbands[2]);
	do{
		threshold(BGRbands[2],maskRGB,otsuTRGB,255,THRESH_BINARY);
		otsuTRGB++;
	}while(countNonZero(maskRGB)>(RGBratio*limitRGB) & otsuTRGB<=255);
	int otsuTHSV = getThreshVal_Otsu_8u(HSVbands[1]);
	do{	
		threshold(HSVbands[1],maskHSV,otsuTHSV,255,THRESH_BINARY_INV);
		otsuTHSV--;
	}while(countNonZero(maskHSV)>(HSVratio*limitHSV) & otsuTHSV>=0); // 0.1
	bitwise_or(maskHSV,maskRGB,maskT);
	int blobSizeBefore = blobs.GetNumBlobs();
    blobs = blobs + CBlobResult( maskT ,Mat(),8);
	blobs.Filter( blobs, B_EXCLUDE, CBlobGetLength(), B_GREATER, bmax );
	blobs.Filter( blobs, B_EXCLUDE, CBlobGetLength(), B_LESS, bmin );
	int blobSizeAfter = blobs.GetNumBlobs();
	Mat newMask(maskT.size(),maskT.type());
    newMask.setTo(0);
    for(;i<blobs.GetNumBlobs();i++){
		double area = blobs.GetBlob(i)->Area();
		if(area < 5000 && area > 400)
			blobs.GetBlob(i)->FillBlob(newMask,CV_RGB(255,255,255),0,0,true);
    }
	if(countNonZero(maskRGB)>400 && countNonZero(maskHSV)>400 && blobSizeBefore!=blobSizeAfter){
		vector<Mat> BGRbands;  split(imgRGBin,BGRbands);
		Mat maskedRGB = applyMaskBandByBand(newMask,BGRbands);
		bitwise_not(newMask,newMask);
		split(imgHSVIn,BGRbands);
		Mat maskedHSV = applyMaskBandByBand(newMask,BGRbands);
		blobs = computeWhiteMaskOtsu(maskedRGB, maskedHSV, blobs, countNonZero(maskRGB),countNonZero(maskHSV),RGBratio, HSVratio, bmin, bmax, i-1);
	}		
	return blobs;
}
	void ChangeResolutionAction::DecreaseTimeWithMask(TimeFrequencyData& data)
	{
		size_t polCount = data.PolarizationCount();
		for(size_t i=0;i<polCount;++i)
		{
			TimeFrequencyData polData(data.MakeFromPolarizationIndex(i));
			const Mask2DCPtr mask = polData.GetSingleMask();
			for(unsigned j=0;j<polData.ImageCount();++j)
			{
				const Image2DCPtr image = polData.GetImage(j);
				polData.SetImage(j, ThresholdTools::ShrinkHorizontally(_timeDecreaseFactor, image.get(), mask.get()));
			}
			data.SetPolarizationData(i, std::move(polData));
		}
		size_t maskCount = data.MaskCount();
		for(size_t i=0;i<maskCount;++i)
		{
			Mask2DCPtr mask = data.GetMask(i);
			Mask2DPtr newMask(new Mask2D(mask->ShrinkHorizontallyForAveraging(_timeDecreaseFactor)));
			data.SetMask(i, std::move(newMask));
		}
	}
	void ChangeResolutionAction::DecreaseTime(TimeFrequencyData &timeFrequencyData)
	{
		if(_useMaskInAveraging)
		{
			DecreaseTimeWithMask(timeFrequencyData);
		}
		else {
			size_t imageCount = timeFrequencyData.ImageCount();
			for(size_t i=0;i<imageCount;++i)
			{
				Image2DCPtr image = timeFrequencyData.GetImage(i);
				Image2DPtr newImage(new Image2D(image->ShrinkHorizontally(_timeDecreaseFactor)));
				timeFrequencyData.SetImage(i, std::move(newImage));
			}
			size_t maskCount = timeFrequencyData.MaskCount();
			for(size_t i=0;i<maskCount;++i)
			{
				Mask2DCPtr mask = timeFrequencyData.GetMask(i);
				Mask2DPtr newMask(new Mask2D(mask->ShrinkHorizontally(_timeDecreaseFactor)));
				timeFrequencyData.SetMask(i, std::move(newMask));
			}
		}
	}
Beispiel #7
0
void FlipCommand::onExecute(Context* context)
{
  ContextWriter writer(context);
  Document* document = writer.document();
  Sprite* sprite = writer.sprite();
  DocumentApi api = document->getApi();

  {
    UndoTransaction undoTransaction(writer.context(),
                                    m_flipMask ?
                                    (m_flipType == raster::algorithm::FlipHorizontal ?
                                     "Flip Horizontal":
                                     "Flip Vertical"):
                                    (m_flipType == raster::algorithm::FlipHorizontal ?
                                     "Flip Canvas Horizontal":
                                     "Flip Canvas Vertical"));

    if (m_flipMask) {
      int x, y;
      Image* image = writer.image(&x, &y);
      if (!image)
        return;

      Mask* mask = NULL;
      bool alreadyFlipped = false;

      // This variable will be the area to be flipped inside the image.
      gfx::Rect bounds(image->getBounds());

      // If there is some portion of sprite selected, we flip the
      // selected region only. If the mask isn't visible, we flip the
      // whole image.
      if (document->isMaskVisible()) {
        mask = document->getMask();

        // Intersect the full area of the image with the mask's
        // bounds, so we don't request to flip an area outside the
        // image's bounds.
        bounds = bounds.createIntersect(gfx::Rect(mask->getBounds()).offset(-x, -y));

        // If the mask isn't a rectangular area, we've to flip the mask too.
        if (mask->getBitmap() != NULL && !mask->isRectangular()) {
          int bgcolor = app_get_color_to_clear_layer(writer.layer());

          // Flip the portion of image specified by the mask.
          mask->offsetOrigin(-x, -y);
          api.flipImageWithMask(image, mask, m_flipType, bgcolor);
          mask->offsetOrigin(x, y);
          alreadyFlipped = true;

          // Flip the mask.
          Image* maskBitmap = mask->getBitmap();
          if (maskBitmap != NULL) {
            // Create a flipped copy of the current mask.
            base::UniquePtr<Mask> newMask(new Mask(*mask));
            newMask->freeze();
            raster::algorithm::flip_image(newMask->getBitmap(),
              maskBitmap->getBounds(), m_flipType);
            newMask->unfreeze();

            // Change the current mask and generate the new boundaries.
            api.copyToCurrentMask(newMask);

            document->generateMaskBoundaries();
          }
        }
      }

      // Flip the portion of image specified by "bounds" variable.
      if (!alreadyFlipped) {
        api.flipImage(image, bounds, m_flipType);
      }
    }
    else {
      // get all sprite cels
      CelList cels;
      sprite->getCels(cels);

      // for each cel...
      for (CelIterator it = cels.begin(); it != cels.end(); ++it) {
        Cel* cel = *it;
        Image* image = sprite->getStock()->getImage(cel->getImage());

        api.setCelPosition
          (sprite, cel,
           (m_flipType == raster::algorithm::FlipHorizontal ?
            sprite->getWidth() - image->getWidth() - cel->getX():
            cel->getX()),
           (m_flipType == raster::algorithm::FlipVertical ?
            sprite->getHeight() - image->getHeight() - cel->getY():
            cel->getY()));

        api.flipImage(image, image->getBounds(), m_flipType);
      }
    }

    undoTransaction.commit();
  }

  update_screen_for_document(document);
}
void SVImageMainWindow::SVImageMainWindowPrivate::setupActions() {
  //
  // "File"-menu
  //
  actionLoad = new QAction("&Open", mw);
  actionLoad->setIcon(QIcon(":icons/document-open.png"));
  actionLoad->setShortcut(QKeySequence::Open);
  connect(actionLoad, SIGNAL(triggered()),
          mw, SLOT(load()));

  actionReload = new QAction("&Reload", mw);
  actionReload->setIcon(QIcon(":icons/view-refresh.png"));
  actionReload->setShortcut(QKeySequence::Refresh);
  actionReload->setEnabled(false);
  connect(actionReload, SIGNAL(triggered()),
          mw, SLOT(reload()));

  actionPrint = new QAction("&Print", mw);
  actionPrint->setIcon(QIcon(":icons/document-print.png"));
  actionPrint->setShortcut(QKeySequence::Print);
  actionPrint->setEnabled(false);
  connect(actionPrint, SIGNAL(triggered()),
          mw, SLOT(print()));

  actionQuit = new QAction("&Quit", mw);
#if QT_VERSION >= 0x040600
  actionQuit->setShortcut(QKeySequence::Quit);
#else
  actionQuit->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
#endif
  connect(actionQuit, SIGNAL(triggered()),
          mw, SLOT(close()));

  //
  // "Plot"-menu
  //
  actionZoomFit = new QAction("Fit to Window", mw);
  actionZoomFit->setIcon(QIcon(":icons/zoom-fit-best.png"));
  actionZoomFit->setEnabled(false);
  connect(actionZoomFit, SIGNAL(triggered()),
          mw, SLOT(zoomFit()));

  actionZoom = new QAction("&Zoom", mw);
  actionZoom->setIcon(QIcon(":icons/page-zoom.png"));
  actionZoom->setCheckable(true);
  actionZoom->setEnabled(false);
  connect(actionZoom, SIGNAL(toggled(bool)),
          mw, SLOT(setZoomEnabled(bool)));

  actionMove = new QAction("&Move", mw);
  actionMove->setIcon(QIcon(":icons/input-mouse.png"));
  actionMove->setCheckable(true);
  actionMove->setChecked(false);
  actionMove->setEnabled(false);
  connect(actionMove, SIGNAL(toggled(bool)),
          mw, SLOT(setMoveEnabled(bool)));
  actionZoom->setChecked(true);

  //
  // "Go"-menu
  //
  actionGoFirst = new QAction("&First", mw);
  actionGoFirst->setShortcut(QKeySequence::MoveToStartOfLine);
  actionGoFirst->setEnabled(false);
  connect(actionGoFirst, SIGNAL(triggered()),
          mw, SLOT(goFirst()));

  actionGoPrevious = new QAction("&Previous", mw);
  actionGoPrevious->setShortcut(QKeySequence::MoveToPreviousPage);
  actionGoPrevious->setIcon(mw->style()->standardIcon(QStyle::SP_MediaSkipBackward));
  actionGoPrevious->setEnabled(false);
  connect(actionGoPrevious, SIGNAL(triggered()),
          mw, SLOT(goPrevious()));

  actionGoNext = new QAction("&Next", mw);
  actionGoNext->setShortcut(QKeySequence::MoveToNextPage);
  actionGoNext->setIcon(mw->style()->standardIcon(QStyle::SP_MediaSkipForward));
  actionGoNext->setEnabled(false);
  connect(actionGoNext, SIGNAL(triggered()),
          mw, SLOT(goNext()));

  actionGoLast = new QAction("&Last", mw);
  actionGoLast->setShortcut(QKeySequence::MoveToEndOfLine);
  actionGoLast->setEnabled(false);
  connect(actionGoLast, SIGNAL(triggered()),
          mw, SLOT(goLast()));

  actionWatchLatest = new QAction("&Watch Latest", mw);
  actionWatchLatest->setCheckable(true);
  actionWatchLatest->setChecked(false);
  actionWatchLatest->setEnabled(false);
  connect(actionWatchLatest, SIGNAL(toggled(bool)),
          mw, SLOT(setWatchLatest(bool)));

  //
  // "Tools"-menu
  //
  actionMaskNew = new QAction("&New", mw);
  actionMaskNew->setEnabled(false);
  connect(actionMaskNew, SIGNAL(triggered()),
          mw, SLOT(newMask()));

  actionMaskLoad = new QAction("&Open", mw);
  actionMaskLoad->setEnabled(false);
  connect(actionMaskLoad, SIGNAL(triggered()),
          mw, SLOT(loadMask()));

  actionMaskSaveAs = new QAction("&Save As ...", mw);
  actionMaskSaveAs->setEnabled(false);
  connect(actionMaskSaveAs, SIGNAL(triggered()),
          mw, SLOT(saveMaskAs()));

  actionMaskByThreshold = new QAction("By Threshold ...", mw);
  actionMaskByThreshold->setEnabled(false);
  connect(actionMaskByThreshold, SIGNAL(triggered()),
          mw, SLOT(setMaskByThreshold()));

  actionMaskAddPoint = new QAction("Add pixel", mw);
  actionMaskAddPoint->setCheckable(true);
  actionMaskAddPoint->setChecked(false);
  actionMaskAddPoint->setEnabled(false);
  connect(actionMaskAddPoint, SIGNAL(toggled(bool)),
          mw, SLOT(setMaskAddPointsEnabled(bool)));

  actionMaskAddPolygon = new QAction("Add polygon", mw);
  actionMaskAddPolygon->setCheckable(true);
  actionMaskAddPolygon->setChecked(false);
  actionMaskAddPolygon->setEnabled(false);
  connect(actionMaskAddPolygon, SIGNAL(toggled(bool)),
          mw, SLOT(setMaskAddPolygonEnabled(bool)));

  actionMaskRemovePoint = new QAction("Remove pixel", mw);
  actionMaskRemovePoint->setCheckable(true);
  actionMaskRemovePoint->setChecked(false);
  actionMaskRemovePoint->setEnabled(false);
  connect(actionMaskRemovePoint, SIGNAL(toggled(bool)),
          mw, SLOT(setMaskRemovePointsEnabled(bool)));

  actionMaskRemovePolygon = new QAction("Remove polygon", mw);
  actionMaskRemovePolygon->setCheckable(true);
  actionMaskRemovePolygon->setChecked(false);
  actionMaskRemovePolygon->setEnabled(false);
  connect(actionMaskRemovePolygon, SIGNAL(toggled(bool)),
          mw, SLOT(setMaskRemovePolygonEnabled(bool)));

  //
  // "Window"-menu
  //
  actionPreviousPlot = new QAction("&Previous Image", mw);
  actionPreviousPlot->setShortcut(QKeySequence::PreviousChild);
  connect(actionPreviousPlot, SIGNAL(triggered()),
          mdiArea, SLOT(activatePreviousSubWindow()));

  actionNextPlot = new QAction("&Next Image", mw);
  actionNextPlot->setShortcut(QKeySequence::NextChild);
  connect(actionNextPlot, SIGNAL(triggered()),
          mdiArea, SLOT(activateNextSubWindow()));

  actionCascadePlots = new QAction("C&ascade Images", mw);
  connect(actionCascadePlots, SIGNAL(triggered()),
          mdiArea, SLOT(cascadeSubWindows()));

  actionTilePlots =  new QAction("&Tile Images", mw);
  connect(actionTilePlots, SIGNAL(triggered()),
          mdiArea, SLOT(tileSubWindows()));

  actionClosePlot = new QAction("&Close Current Image", mw);
  actionClosePlot->setShortcut(QKeySequence::Close);
  connect(actionClosePlot, SIGNAL(triggered()),
          mdiArea, SLOT(closeActiveSubWindow()));

  actionCloseAllPlots = new QAction("Close &All Images", mw);
  connect(actionCloseAllPlots, SIGNAL(triggered()),
          mdiArea, SLOT(closeAllSubWindows()));

  //
  // "Help"-menu
  //
  actionAbout = new QAction("&About", mw);
  connect(actionAbout, SIGNAL(triggered()),
          mw, SLOT(about()));


  actionGroupPlotPicker = new QActionGroup(mw);
  actionGroupPlotPicker->addAction(actionZoom);
  actionGroupPlotPicker->addAction(actionMove);

  actionGroupPlotPicker->addAction(actionMaskAddPoint);
  actionGroupPlotPicker->addAction(actionMaskAddPolygon);
  actionGroupPlotPicker->addAction(actionMaskRemovePoint);
  actionGroupPlotPicker->addAction(actionMaskRemovePolygon);
}