Ejemplo n.º 1
0
int main(){

	PNG imageIn=PNG("in.png");
	PNG imageOut= PNG(imageIn.width(), imageIn.height());
	size_t width=imageIn.width();
	size_t height=imageIn.height();


	for(size_t x=0; x<imageIn.width(); x++){
		
		for(size_t y=0; y<imageIn.height(); y++){
			
			RGBAPixel * outp= imageIn(x,y);
			imageOut(width-x-1,height-y-1)->red=outp->red;
			imageOut(width-x-1,height-y-1)->blue=outp->blue;
			imageOut(width-x-1,height-y-1)->green= outp->green;


		}
	}
	imageOut.writeToFile("out.png");
	return 0;


}
  unsigned int cvLabel (IplImage const *img, IplImage *imgOut, CvBlobs &blobs)
  {
    CV_FUNCNAME("cvLabel");
    __CV_BEGIN__;
    {
      CV_ASSERT(img&&(img->depth==IPL_DEPTH_8U)&&(img->nChannels==1));
      CV_ASSERT(imgOut&&(imgOut->depth==IPL_DEPTH_LABEL)&&(imgOut->nChannels==1));

      unsigned int numPixels=0;

      cvSetZero(imgOut);

      CvLabel label=0;
      cvReleaseBlobs(blobs);

      unsigned int stepIn = img->widthStep / (img->depth / 8);
      unsigned int stepOut = imgOut->widthStep / (imgOut->depth / 8);
      unsigned int imgIn_width = img->width;
      unsigned int imgIn_height = img->height;
      unsigned int imgIn_offset = 0;
      unsigned int imgOut_width = imgOut->width;
      unsigned int imgOut_height = imgOut->height;
      unsigned int imgOut_offset = 0;
      if(img->roi)
      {
	imgIn_width = img->roi->width;
	imgIn_height = img->roi->height;
	imgIn_offset = img->roi->xOffset + (img->roi->yOffset * stepIn);
      }
      if(imgOut->roi)
      {
	imgOut_width = imgOut->roi->width;
	imgOut_height = imgOut->roi->height;
	imgOut_offset = imgOut->roi->xOffset + (imgOut->roi->yOffset * stepOut);
      }

      unsigned char *imgDataIn = (unsigned char *)img->imageData + imgIn_offset;
      CvLabel *imgDataOut = (CvLabel *)imgOut->imageData + imgOut_offset;

#define imageIn(X, Y) imgDataIn[(X) + (Y)*stepIn]
#define imageOut(X, Y) imgDataOut[(X) + (Y)*stepOut]

      CvLabel lastLabel = 0;
      CvBlob *lastBlob = NULL;

      for (unsigned int y=0; y<imgIn_height; y++)
      {
	for (unsigned int x=0; x<imgIn_width; x++)
	{
	  if (imageIn(x, y))
	  {
	    bool labeled = imageOut(x, y);

	    if ((!imageOut(x, y))&&((y==0)||(!imageIn(x, y-1))))
	    {
	      labeled = true;

	      // Label contour.
	      label++;
	      CV_ASSERT(label!=CV_BLOB_MAX_LABEL);

	      imageOut(x, y) = label;
	      numPixels++;

	      if (y>0)
		imageOut(x, y-1) = CV_BLOB_MAX_LABEL;

	      CvBlob *blob = new CvBlob;
	      blob->label = label;
	      blob->area = 1;
	      blob->minx = x; blob->maxx = x;
	      blob->miny = y; blob->maxy = y;
	      blob->m10=x; blob->m01=y;
	      blob->m11=x*y;
	      blob->m20=x*x; blob->m02=y*y;
	      blob->internalContours.clear();
	      blobs.insert(CvLabelBlob(label,blob));

              lastLabel = label;
	      lastBlob = blob;

	      blob->contour.startingPoint = cvPoint(x, y);

	      unsigned char direction=1;
	      unsigned int xx = x;
	      unsigned int yy = y;


	      bool contourEnd = false;

	      do
	      {
		for (unsigned int numAttempts=0; numAttempts<3; numAttempts++)
		{
		  bool found = false;

		  for (unsigned char i=0; i<3; i++)
		  {
		    int nx = xx+movesE[direction][i][0];
		    int ny = yy+movesE[direction][i][1];
		    if ((nx<imgIn_width)&&(nx>=0)&&(ny<imgIn_height)&&(ny>=0))
		    {
		      if (imageIn(nx, ny))
		      {
			found = true;

			blob->contour.chainCode.push_back(movesE[direction][i][3]);

			xx=nx;
			yy=ny;

			direction=movesE[direction][i][2];
			break;
		      }
		      else
		      {
			imageOut(nx, ny) = CV_BLOB_MAX_LABEL;
		      }
		    }
		  }

		  if (!found)
		    direction=(direction+1)%4;
		  else
		  {
		    if (imageOut(xx, yy) != label)
		    {
		      imageOut(xx, yy) = label;
		      numPixels++;

		      if (xx<blob->minx) blob->minx = xx;
		      else if (xx>blob->maxx) blob->maxx = xx;
		      if (yy<blob->miny) blob->miny = yy;
		      else if (yy>blob->maxy) blob->maxy = yy;

		      blob->area++;
		      blob->m10+=xx; blob->m01+=yy;
		      blob->m11+=xx*yy;
		      blob->m20+=xx*xx; blob->m02+=yy*yy;
		    }

		    break;
		  }
		  
		  if (contourEnd = ((xx==x) && (yy==y) && (direction==1)))
		    break;
		}
	      }
	      while (!contourEnd);

	    }

	    if ((y+1<imgIn_height)&&(!imageIn(x, y+1))&&(!imageOut(x, y+1)))
	    {
	      labeled = true;

	      // Label internal contour
	      CvLabel l;
	      CvBlob *blob = NULL;

	      if (!imageOut(x, y))
	      {
		l = imageOut(x-1, y);

		imageOut(x, y) = l;
		numPixels++;

                if (l==lastLabel)
                  blob = lastBlob;
                else
                {
                  blob = blobs.find(l)->second;
                  lastLabel = l;
                  lastBlob = blob;
                }
		blob->area++;
		blob->m10+=x; blob->m01+=y;
		blob->m11+=x*y;
		blob->m20+=x*x; blob->m02+=y*y;
	      }
	      else
	      {
		l = imageOut(x, y);

                if (l==lastLabel)
                  blob = lastBlob;
                else
                {
                  blob = blobs.find(l)->second;
                  lastLabel = l;
                  lastBlob = blob;
                }
	      }

	     imageOut(x, y+1) = CV_BLOB_MAX_LABEL;

	      CvContourChainCode *contour = new CvContourChainCode;
	      contour->startingPoint = cvPoint(x, y);

	      unsigned char direction = 3;
	      unsigned int xx = x;
	      unsigned int yy = y;

	      do
	      {
		for (unsigned int numAttempts=0; numAttempts<3; numAttempts++)
		{
		  bool found = false;

		  for (unsigned char i=0; i<3; i++)
		  {
		    int nx = xx+movesI[direction][i][0];
		    int ny = yy+movesI[direction][i][1];
		    if (imageIn(nx, ny))
		    {
		      found = true;

		      contour->chainCode.push_back(movesI[direction][i][3]);

		      xx=nx;
		      yy=ny;

		      direction=movesI[direction][i][2];
		      break;
		    }
		    else
		    {
		      imageOut(nx, ny) = CV_BLOB_MAX_LABEL;
		    }
		  }

		  if (!found)
		    direction=(direction+1)%4;
		  else
		  {
		    if (!imageOut(xx, yy))
		    {
		      imageOut(xx, yy) = l;
		      numPixels++;

		      blob->area++;
		      blob->m10+=xx; blob->m01+=yy;
		      blob->m11+=xx*yy;
		      blob->m20+=xx*xx; blob->m02+=yy*yy;
		    }

		    break;
		  }
		}
	      }
	      while (!(xx==x && yy==y));

	      blob->internalContours.push_back(contour);
	    }
	    if (!labeled)
	    {
	      CvLabel l = imageOut(x-1, y);

	      imageOut(x, y) = l;
	      numPixels++;

	      CvBlob *blob = NULL;
              if (l==lastLabel)
                blob = lastBlob;
              else
              {
                blob = blobs.find(l)->second;
                lastLabel = l;
                lastBlob = blob;
              }
	      blob->area++;
	      blob->m10+=x; blob->m01+=y;
	      blob->m11+=x*y;
	      blob->m20+=x*x; blob->m02+=y*y;
	    }
	  }
	}
      }

      for (CvBlobs::iterator it=blobs.begin(); it!=blobs.end(); ++it)
      {
	cvCentroid((*it).second);

        (*it).second->u11 = (*it).second->m11 - ((*it).second->m10*(*it).second->m01)/(*it).second->m00;
        (*it).second->u20 = (*it).second->m20 - ((*it).second->m10*(*it).second->m10)/(*it).second->m00;
        (*it).second->u02 = (*it).second->m02 - ((*it).second->m01*(*it).second->m01)/(*it).second->m00;

        double m00_2 = (*it).second->m00 * (*it).second->m00;

        (*it).second->n11 = (*it).second->u11 / m00_2;
        (*it).second->n20 = (*it).second->u20 / m00_2;
        (*it).second->n02 = (*it).second->u02 / m00_2;

        (*it).second->p1 = (*it).second->n20 + (*it).second->n02;

        double nn = (*it).second->n20 - (*it).second->n02;
        (*it).second->p2 = nn*nn + 4.*((*it).second->n11*(*it).second->n11);
      }

      return numPixels;

    }
    __CV_END__;
  }
Ejemplo n.º 3
0
int main( int /*argc*/, char **argv )
{
	//  ENABLE_LOG( isis::glance::data::Debug, isis::util::DefaultMsgPrint, isis::verbose_info );
	//  ENABLE_LOG( isis::glance::util::Debug, isis::util::DefaultMsgPrint, isis::verbose_info );
	ENABLE_LOG( isis::glance::data::Runtime, isis::util::DefaultMsgPrint, isis::verbose_info );
	//  const int dstr = atoi(argv[1]);
	//  const int sstr1 = atoi(argv[2]);
	//  const int sstr2 = atoi(argv[3]);
	//  oil_init();
	//  size_t length = 10;
	//  const int32_t perm[] = { 0,2,4,6,8,1,3,5,7,9 };
	//  const uint16_t src[] = { 10,11,12,13,14,15,16,17,18,19 };
	//  uint16_t dest[10];
	//  oil_permute_u16( dest, dstr, src, sstr1, perm, sstr2, length );
	//
	//  for( size_t i = 0; i < length; i++ ) {
	//      std::cout << (float)dest[i] << " ";
	//  }
	//  std::cout << std::endl;


	isis::util::slist paths;
	paths.push_back( argv[1] );

	boost::timer timer;

	isis::glance::data::IOFactory::setUseProposedDataType( true );
	isis::glance::data::IOFactory::setProposedDataType( isis::glance::data::ImageDataProperties::SCALAR, isis::glance::data::types::UINT16_T );

	isis::glance::data::Image::SharedPointer image = isis::glance::data::IOFactory::load( paths ).front();

	const isis::glance::data::Volume &vol = image->operator[]( 0 );

	isis::glance::data::Volume::fvec perp;
	perp[0] = 1;
	perp[1] = 0;
	perp[2] = 0;
	isis::glance::data::Volume::ivec coords;
	coords[0] = image->image_size[0] / 2;
	coords[1] = image->image_size[1] / 2;
	coords[2] = image->image_size[2] / 2;

	const size_t iterations = 5000;
	const bool aligned = true;

	isis::glance::data::Slice sliceSagittal = vol.extractSlice( perp, coords, aligned );
	isis::data::Chunk chunkSag( sliceSagittal,  sliceSagittal.getSizeAsVector()[0], sliceSagittal.getSizeAsVector()[1], 1, 1, true );
	isis::data::Image imageOutSag( chunkSag );
	isis::data::IOFactory::write( imageOutSag, "/tmp/sagittal.nii" );

	perp[0] = 0;
	perp[1] = 1;
	perp[2] = 0;

	isis::glance::data::Slice sliceCoronal = vol.extractSlice( perp, coords, aligned );
	isis::data::Chunk chunkCoronal( sliceCoronal,  sliceCoronal.getSizeAsVector()[0], sliceCoronal.getSizeAsVector()[1], 1, 1, true );
	isis::data::Image imageOutCoronal( chunkCoronal );
	isis::data::IOFactory::write( imageOutCoronal, "/tmp/coronal.nii" );


	perp[0] = 0;
	perp[1] = 0;
	perp[2] = 1;
	isis::glance::data::Slice slice = vol.extractSlice( perp, coords, aligned );

	isis::data::Chunk chunk( slice,  slice.getSizeAsVector()[0], slice.getSizeAsVector()[1], 1, 1, true );
	isis::data::Image imageOut( chunk );

	isis::data::IOFactory::write( imageOut, "/tmp/axial.nii" );

	std::vector<isis::glance::data::Slice> slices = vol.extractAllSlices( perp );

	for ( size_t i = 0; i < slices.size(); i++ ) {
		isis::data::Chunk chunk( slices[i],  slices[i].getSizeAsVector()[0], slices[i].getSizeAsVector()[1], 1, 1, true );
		isis::data::Image imageOut( chunk );
		std::stringstream name;
		name << "/tmp/series" << i << ".nii";
		isis::data::IOFactory::write( imageOut, name.str() );
	}




	return 0;
}
Ejemplo n.º 4
0
	const QImage& GetEmoji(const uint32_t main, const uint32_t ext, const EmojiSizePx size)
	{
		assert(main > 0);
		assert(size >= EmojiSizePx::Min);
		assert(size <= EmojiSizePx::Max);

		static QImage empty;

		Loading_.waitForFinished();
		if (!Loading_.result())
		{
			return empty;
		}

		const auto sizeToSearch = ((size == EmojiSizePx::Auto) ? GetEmojiSizeForCurrentUiScale() : (int32_t)size);
        
		const auto info = GetEmojiInfoByCodepoint(main, ext);
		if (!info)
		{
			return empty;
		}
		assert(info->Index_ >= 0);

		const auto key = MakeCacheKey(info->Index_, sizeToSearch);
		auto cacheIter = EmojiCache_.find(key);
		if (cacheIter != EmojiCache_.end())
		{
			assert(!cacheIter->second.isNull());
			return cacheIter->second;
		}

        QImage image;

        if (platform::is_apple())
        {
            QImage imageOut(QSize(sizeToSearch, sizeToSearch), QImage::Format_ARGB32);
            imageOut.fill(Qt::transparent);
            
            QPainter painter(&imageOut);
            
            painter.setRenderHint(QPainter::Antialiasing);
            painter.setRenderHint(QPainter::TextAntialiasing);
            painter.setRenderHint(QPainter::SmoothPixmapTransform);

            painter.setPen(Qt::SolidLine);
            painter.setPen(QColor::fromRgb(0, 0, 0));
            
            QRect r(0, Utils::is_mac_retina()?-6:-2, sizeToSearch, sizeToSearch+20);
            
            Utils::SChar ch(main, ext);
            QFont f = QFont(QStringLiteral("AppleColorEmoji"), sizeToSearch);
            painter.setFont(f);
            painter.drawText(r, Qt::AlignHCenter, ch.ToQString());
            
            painter.end();
            
            image = imageOut;
        }
        else
        {
            const auto &meta = GetMetaBySize(sizeToSearch);
            
            auto emojiSetIter = LoadEmojiSetForSizeIfNeeded(meta);
            
            QRect r(0, 0, meta.SizePx_, meta.SizePx_);
            const auto offsetX = (info->Index_ * meta.SizePx_);
            r.translate(offsetX, 0);
            
            image = emojiSetIter->second.copy(r);
        }
        
        const auto result = EmojiCache_.emplace(key, std::move(image));
        assert(result.second);
        
		return result.first->second;
	}