예제 #1
0
void Mask::ApplyToRGBImage(TImage* const image, const TColor& color) const
{
  // Using generics, we allow any Color class that has .red(), .green(), and .blue() member functions
  // to be used to specify the color.
  if(image->GetLargestPossibleRegion() != this->GetLargestPossibleRegion())
  {
    std::cerr << "Image and mask must be the same size!" << std::endl
              << "Image region: " << image->GetLargestPossibleRegion() << std::endl
              << "Mask region: " << this->GetLargestPossibleRegion() << std::endl;
    return;
  }

  // Color the hole pixels in the image.
  typename TImage::PixelType holeValue;
  holeValue.SetSize(image->GetNumberOfComponentsPerPixel());
  holeValue.Fill(0);
  if(image->GetNumberOfComponentsPerPixel() >= 3)
  {
    holeValue[0] = color.red();
    holeValue[1] = color.green();
    holeValue[2] = color.blue();
  }

  itk::ImageRegionConstIterator<Mask> maskIterator(this, this->GetLargestPossibleRegion());

  while(!maskIterator.IsAtEnd())
  {
    if(this->IsHole(maskIterator.GetIndex()))
    {
      image->SetPixel(maskIterator.GetIndex(), holeValue);
    }

    ++maskIterator;
  }
}
예제 #2
0
int TImageTga::save (const TImage* pktIMAGE)
{

  TColor     tColor;
  TColor     tPixel;
  ofstream   sFile;
  size_t     zWidth  = pktIMAGE->width();
  size_t     zHeight = pktIMAGE->height();
  Byte*      pbRow   = new Byte [zWidth * 3];

  sFile.open (tFileName.c_str(), ios::binary | ios::out);

  sFile << (Byte) 0;                         // Length of identifier string
  sFile << (Byte) 0;                         // Color map type (0 = no color map)
  sFile << (Byte) 2;                         // Image type (2 = RGB)
  sFile << (Byte) 0;                         // First color map entry (LSB)
  sFile << (Byte) 0;                         //   "     "    "    "   (MSB)
  sFile << (Byte) 0;                         // Entries in color map (LSB)
  sFile << (Byte) 0;                         //    "     "   "    "  (MSB)
  sFile << (Byte) 0;                         // Size of color map entry
  sFile << (Byte) 0;                         // X origin of image (LSB)
  sFile << (Byte) 0;                         // "    "    "   "   (MSB)
  sFile << (Byte) 0;                         // Y origin of image (LSB)
  sFile << (Byte) 0;                         // "    "    "   "   (MSB)
  sFile << (Byte) (zWidth % 256);
  sFile << (Byte) (zWidth / 256);
  sFile << (Byte) (zHeight % 256);
  sFile << (Byte) (zHeight / 256);
  sFile << (Byte) 24;                        // Pixel size (24 bits)
  sFile << (Byte) 0;                         // Attributes (0 = origin in lower left)

  for (int J = (zHeight - 1) ; ( J >= 0 ) ;J--)
  {
    for (size_t I = 0; ( I < zWidth ) ;I++)
    {
      tPixel = pktIMAGE->getPixel (I, J);
      tPixel.clamp();
      tColor = tPixel.convertTo24Bits();

      pbRow [I * 3]     = (Byte) tColor.blue();
      pbRow [I * 3 + 1] = (Byte) tColor.green();
      pbRow [I * 3 + 2] = (Byte) tColor.red();
    }
    sFile.write ((char*)pbRow, zWidth * 3);
  }

  sFile.close();

  delete[] pbRow;
  
  return 0;
  
}  /* save() */