void ImageProcessing::swapColours( FrameBuffer const * frame, FrameBuffer * outFrame, Rect bbox, unsigned int subSample, ColourDefinition const & find, RawPixel const & replace ) { Pixel pixel; unsigned int tlx = bbox.topLeft().x(); unsigned int tly = bbox.topLeft().y(); unsigned int brx = bbox.bottomRight().x(); unsigned int bry = bbox.bottomRight().y(); FrameBufferIterator iter( frame, 0, 0 ); if (outFrame == 0 ) { outFrame = const_cast<FrameBuffer *> ( frame ); } FrameBufferIterator outIter( outFrame, 0, 0 ); for( unsigned int i = tly; i < bry; i += subSample ) { iter.goPosition( i, 0 ); outIter.goPosition( i, 0 ); for( unsigned int j = tlx; j < brx; j += subSample, iter.goRight( subSample ), outIter.goRight( subSample ) ) { iter.getPixel( & pixel ); if ( find.isMatch( pixel ) ) { pixel = replace; } outIter.setPixel( pixel ); } } }
int main() { std::vector<int> vi; std::istream_iterator<int> inIter(std::cin), eof; std::ostream_iterator<int> outIter(std::cout, " "); while (inIter != eof) vi.push_back(*inIter++); sort(vi.begin(), vi.end()); copy(vi.begin(), vi.end(), outIter); std::cout << std::endl; return 0; }
/// /// Ostream operator overload. Utilized ostream_iterator to /// output vector of locations. /// std::ostream& operator<<(std::ostream& os, const Word& oWord) { os << oWord.getString() << std::endl << " "; locOStreamiter outIter(os, ", "); std::copy(oWord.locVec.begin(), oWord.locVec.end(), outIter); os << "\b" << "\b" <<" " << " "; // Utilized to remove comma at end of stream. return os; }
int main () { typedef vector<int> IVec; vector<int> v1 (10); for (int loc = 0; loc < v1.size (); loc++) v1[loc] = loc; vector<int> v2; insert_iterator<IVec> i (v2, v2.begin ()); copy (v1.begin (), v1.end (), i); ostream_iterator<int> outIter (cout, " "); copy (v2.begin (), v2.end (), outIter); cout << endl; return 0; }
int copy4_test(int, char**) { std::cout<<"Results of copy4_test:"<<std::endl; typedef std::vector<int> IVec; std::vector<int> v1(10); for(int loc = 0; loc < v1.size(); loc++) v1[loc] = loc; std::vector<int> v2; std::insert_iterator<IVec> i(v2, v2.begin()); std::copy(v1.begin(), v1.end(), i); std::ostream_iterator<int> outIter(std::cout, " "); std::copy(v2.begin(), v2.end(), outIter); std::cout << std::endl; return 0; }
void ImageProcessing::medianFilter( FrameBuffer const * frame, FrameBuffer * outFrame, unsigned int subSample ) { int red, green, blue; RawPixel pixel; FrameBufferIterator iter( frame, 0, 0 ); RawPixel setPixel; if (outFrame == 0 ) { outFrame = const_cast<FrameBuffer *> ( frame ); } FrameBufferIterator outIter( outFrame, 0, 0 ); for( unsigned int i = 0; i < frame->height - 1; i += subSample ) { iter.goPosition( i, 0 ); outIter.goPosition( i, 0 ); for( unsigned int j = 0; j < frame->width - 1; j += subSample, iter.goRight( subSample ), outIter.goRight( 1 ) ) { iter.getPixel( & pixel ); red = pixel.red; green = pixel.green; blue = pixel.blue; iter.getPixel( & pixel, frame->bytesPerPixel ); red = red + pixel.red; green = green + pixel.green; blue = blue + pixel.blue; iter.getPixel( & pixel, frame->bytesPerLine ); red = red + pixel.red; green = green + pixel.green; blue = blue + pixel.blue; iter.getPixel( & pixel, frame->bytesPerLine + frame->bytesPerPixel ); red = red + pixel.red; green = green + pixel.green; blue = blue + pixel.blue; setPixel = RawPixel( red/4, green/4, blue/4 ); outIter.setPixel( setPixel, 0 ); } } }
Iterator MultiLayerNet::getOutLayer() const{ Iterator outIter(outNeurons); return outIter; }
enum ImageProcessing::ErrorCode ImageProcessing::doFloodFill( FrameBuffer * frame, FrameBuffer * outFrame, Point p, RawPixel seed, unsigned int threshold, ColourDefinition const * colour, unsigned int subSample, FloodFillState * state ) { Pixel pixel; Pixel outPixel; Pixel neighbour; unsigned int diff; //int ret; FrameBufferIterator iter( frame, 0, 0 ); FrameBufferIterator outIter( outFrame, 0, 0 ); Point stack[ STACK_SIZE ]; Point c; enum ErrorCode err = NO_ERROR; // Use stackIndex = 0 as underflow check unsigned int stackIndex = 1; #ifndef Q_NODEBUG // std::cout << __PRETTY_FUNCTION__ << " called at (" << p.x() << ',' << p.y() << ")" << " with colour " << seed << std::endl; #endif // state->initialize(); // outFrame->fill( RawPixel(0,0,0) ); // Set to black. // If the seed is black, the flood fill will get stuck in an // infinite loop. So, we skip floodfills on black seeds. if( ( seed.red == 0 ) && ( seed.green == 0 ) && ( seed.blue == 0) ) { // Fudge the seed to be not all black. seed.blue = 1; } if( iter.goPosition( p.y(), p.x() ) || outIter.goPosition( p.y(), p.x() ) ) { err = INVALID_SEED_POINT; goto exit; } // Push the initial point onto the stack stack[stackIndex++] = p; while( stackIndex > 1 ) { if ( stackIndex >= STACK_SIZE - 4 ) { std::cerr << __PRETTY_FUNCTION__ << " ERROR: possible stack overflow " << stackIndex << std::endl; err = STACK_OVERFLOW; goto exit; } c = stack[--stackIndex]; #ifndef Q_NODEBUG // std::cout << " processing point (" << c.x() << ',' << c.y() << ")" << std::endl; #endif if( iter.goPosition( c.y(), c.x() ) || outIter.goPosition( c.y(), c.x() ) ) { err = OUT_OF_BOUNDS; goto exit; } iter.getPixel( & pixel, 0 ); outIter.getPixel( & outPixel, 0 ); // if ( ! ImageProcessing::isChecked( outPixel ) ) if ( ( outPixel.red == 0 ) && ( outPixel.green == 0 ) && ( outPixel.blue == 0 ) ) { if ( ( ( pixel.red < BRIGHT_PIXEL) && ( pixel.red > DARK_PIXEL ) ) && ( pixel.green > DARK_PIXEL ) && ( pixel.blue > DARK_PIXEL ) ) { state->addPoint( c, pixel ); outIter.setPixel( seed, 0 ); iter.setPixel( seed, 0 ); if ( c.x() >= subSample ) { iter.getPixel( &neighbour, -subSample * frame->bytesPerPixel ); diff = pixel.diffIntensity( neighbour ); if ( ( diff <= threshold ) && ( (colour == 0 ) || colour->isMatch( pixel ) ) ) { stack[stackIndex++] = Point( c.x() - subSample, c.y() ); } } if ( c.x() < (frame->width - 1 - subSample) ) { iter.getPixel( &neighbour, + subSample * frame->bytesPerPixel ); diff = pixel.diffIntensity( neighbour ); if ( ( diff <= threshold ) && ( (colour == 0 ) || colour->isMatch( pixel ) ) ) { stack[stackIndex++] = Point( c.x() + subSample, c.y() ); } } if ( c.y() >= subSample ) { iter.getPixel( &neighbour, - subSample * frame->bytesPerLine ); diff = pixel.diffIntensity( neighbour ); if ( ( diff <= threshold ) && ( (colour == 0 ) || colour->isMatch( pixel ) ) ) { stack[stackIndex++] = Point( c.x(), c.y() - subSample ); } } if ( c.y() < (frame->height - 1 - subSample) ) { iter.getPixel( &neighbour, + subSample * frame->bytesPerLine ); diff = pixel.diffIntensity( neighbour ); if ( ( diff <= threshold ) && ( (colour == 0 ) || colour->isMatch( pixel ) ) ) { stack[stackIndex++] = Point( c.x(), c.y() + subSample ); } } } else { // mark the pixel as checked outIter.setPixel( seed, 0 ); iter.setPixel( seed, 0 ); } } } state->setSumX( state->sumX() * subSample * subSample ); state->setSumY( state->sumY() * subSample * subSample ); state->setSize( state->size() * subSample * subSample ); exit: return err; }
void mitk::MRNormLinearStatisticBasedFilter::InternalComputeMask(itk::Image<TPixel, VImageDimension>* itkImage) { // Define all necessary Types typedef itk::Image<TPixel, VImageDimension> ImageType; typedef itk::Image<int, VImageDimension> MaskType; typedef itk::LabelStatisticsImageFilter<ImageType, MaskType> FilterType; typedef itk::MinimumMaximumImageCalculator<ImageType> MinMaxComputerType; typename MaskType::Pointer itkMask0 = MaskType::New(); mitk::CastToItkImage(this->GetMask(), itkMask0); typename ImageType::Pointer outImage = ImageType::New(); mitk::CastToItkImage(this->GetOutput(0), outImage); typename MinMaxComputerType::Pointer minMaxComputer = MinMaxComputerType::New(); minMaxComputer->SetImage(itkImage); minMaxComputer->Compute(); typename FilterType::Pointer labelStatisticsImageFilter = FilterType::New(); labelStatisticsImageFilter->SetUseHistograms(true); labelStatisticsImageFilter->SetHistogramParameters(256, minMaxComputer->GetMinimum(),minMaxComputer->GetMaximum()); labelStatisticsImageFilter->SetInput( itkImage ); labelStatisticsImageFilter->SetLabelInput(itkMask0); labelStatisticsImageFilter->Update(); double median0 = labelStatisticsImageFilter->GetMedian(1); double mean0 = labelStatisticsImageFilter->GetMean(1); double stddev = labelStatisticsImageFilter->GetSigma(1); double modulo0=0; { auto histo = labelStatisticsImageFilter->GetHistogram(1); double maxFrequency=0; for (auto hIter=histo->Begin();hIter!=histo->End();++hIter) { if (maxFrequency < hIter.GetFrequency()) { maxFrequency = hIter.GetFrequency(); modulo0 = (histo->GetBinMin(0,hIter.GetInstanceIdentifier()) + histo->GetBinMax(0,hIter.GetInstanceIdentifier())) / 2.0; } } } double value0=0; switch (m_CenterMode) { case MRNormLinearStatisticBasedFilter::MEAN: value0=mean0; break; case MRNormLinearStatisticBasedFilter::MEDIAN: value0=median0; break; case MRNormLinearStatisticBasedFilter::MODE: value0=modulo0; break; } double offset = value0; double scaling = stddev; if (scaling < 0.0001) return; itk::ImageRegionIterator<ImageType> inIter(itkImage, itkImage->GetLargestPossibleRegion()); itk::ImageRegionIterator<ImageType> outIter(outImage, outImage->GetLargestPossibleRegion()); while (! inIter.IsAtEnd()) { TPixel value = inIter.Value(); outIter.Set((value - offset) / scaling); ++inIter; ++outIter; } }