int main() { // Load images from file SimpleImage imgA("a.jpg"); SimpleImage imgA2("a_2.jpg"); SimpleImage imgB("b.jpg"); //float y, i, q; // Initialize result image SimpleImage result(imgA.width(), imgA.height(), RGBColor(0, 0, 0)); // Iterate over pixels and set color for result image for (int y = 0; y < imgA.height(); ++y) { for (int x = 0; x < imgA.width(); ++x) { RGBColor p1 = imgA(x, y); RGBColor p2 = imgA2(x,y); RGBColor q1 = imgB(x,y); RGBColor q2; YIQ p1p(p1); YIQ p2p(p2); q2.r = p1p.y; q2.g = p1p.i; q2.b = p1p.q; result.set(x, y, q2); //printf("RGB: %.2f %.2f %.2f - YIQ %.2f - %.2f - %.2f\n", p.r , p.g , p.b , pp.y, pp.i, pp.q); } } // Save result image to file result.save("./b_2.jpg"); //system("pause"); return 0; }
/** * Put masks to white, images are conserved * * \param[out] maskLeft Mask of the left image (initialized to corresponding image size). * \param[out] maskRight Mask of the right image (initialized to corresponding image size). * * \return True. */ virtual bool computeMask( image::Image< unsigned char > & maskLeft, image::Image< unsigned char > & maskRight ) { std::vector< matching::IndMatch > vec_KVLDMatches; image::Image< unsigned char > imageL, imageR; image::ReadImage( _sLeftImage.c_str(), &imageL ); image::ReadImage( _sRightImage.c_str(), &imageR ); image::Image< float > imgA ( imageL.GetMat().cast< float >() ); image::Image< float > imgB(imageR.GetMat().cast< float >()); std::vector< Pair > matchesFiltered, matchesPair; for( std::vector< matching::IndMatch >::const_iterator iter_match = _vec_PutativeMatches.begin(); iter_match != _vec_PutativeMatches.end(); ++iter_match ) { matchesPair.push_back( std::make_pair( iter_match->i_, iter_match->j_ ) ); } std::vector< double > vec_score; //In order to illustrate the gvld(or vld)-consistant neighbors, the following two parameters has been externalized as inputs of the function KVLD. openMVG::Mat E = openMVG::Mat::Ones( _vec_PutativeMatches.size(), _vec_PutativeMatches.size() ) * ( -1 ); // gvld-consistancy matrix, intitialized to -1, >0 consistancy value, -1=unknow, -2=false std::vector< bool > valide( _vec_PutativeMatches.size(), true );// indices of match in the initial matches, if true at the end of KVLD, a match is kept. size_t it_num = 0; KvldParameters kvldparameters;//initial parameters of KVLD //kvldparameters.K = 5; while ( it_num < 5 && kvldparameters.inlierRate > KVLD( imgA, imgB, _vec_featsL, _vec_featsR, matchesPair, matchesFiltered, vec_score, E, valide, kvldparameters ) ) { kvldparameters.inlierRate /= 2; std::cout<<"low inlier rate, re-select matches with new rate="<<kvldparameters.inlierRate<<std::endl; kvldparameters.K = 2; it_num++; } bool bOk = false; if( !matchesPair.empty()) { // Get mask getKVLDMask( &maskLeft, &maskRight, _vec_featsL, _vec_featsR, matchesPair, valide, E); bOk = true; } else{ maskLeft.fill( 0 ); maskRight.fill( 0 ); } return bOk; }
void Decompress(const FasTC::DecompressionJob &dcj, const EWrapMode wrapMode, bool bDebugImages) { const bool bTwoBitMode = dcj.Format() == FasTC::eCompressionFormat_PVRTC2; const uint32 w = dcj.Width(); const uint32 h = dcj.Height(); assert(w > 0); assert(h > 0); assert(bTwoBitMode || w % 4 == 0); assert(!bTwoBitMode || w % 8 == 0); assert(h % 4 == 0); // First, extract all of the block information... std::vector<Block> blocks; const uint32 blocksW = bTwoBitMode? (w / 8) : (w / 4); const uint32 blocksH = h / 4; blocks.reserve(blocksW * blocksH); for(uint32 j = 0; j < blocksH; j++) { for(uint32 i = 0; i < blocksW; i++) { // The blocks are initially arranged in morton order. Let's // linearize them... uint32 idx = Interleave(j, i); uint32 offset = idx * kBlockSize; blocks.push_back( Block(dcj.InBuf() + offset) ); } } assert(blocks.size() > 0); // Extract the endpoints into A and B images Image imgA(blocksW, blocksH); Image imgB(blocksW, blocksH); for(uint32 j = 0; j < blocksH; j++) { for(uint32 i = 0; i < blocksW; i++) { uint32 idx = j * blocksW + i; assert(idx < static_cast<uint32>(blocks.size())); Block &b = blocks[idx]; imgA(i, j) = b.GetColorA(); imgB(i, j) = b.GetColorB(); } } // Change the pixel mode so that all of the pixels are at the same // bit depth. const uint8 scaleDepths[4] = { 4, 5, 5, 5 }; imgA.ChangeBitDepth(scaleDepths); if(bDebugImages) imgA.DebugOutput("UnscaledImgA"); imgB.ChangeBitDepth(scaleDepths); if(bDebugImages) imgB.DebugOutput("UnscaledImgB"); // Go through and change the alpha value of any pixel that came from // a transparent block. For some reason, alpha is not treated the same // as the other channels (to minimize hardware costs?) and the channels // do not their MSBs replicated. for(uint32 j = 0; j < blocksH; j++) { for(uint32 i = 0; i < blocksW; i++) { const uint32 blockIdx = j * blocksW + i; Block &b = blocks[blockIdx]; uint8 bitDepths[4]; b.GetColorA().GetBitDepth(bitDepths); if(bitDepths[0] > 0) { Pixel &p = imgA(i, j); p.A() = p.A() & 0xFE; } b.GetColorB().GetBitDepth(bitDepths); if(bitDepths[0] > 0) { Pixel &p = imgB(i, j); p.A() = p.A() & 0xFE; } } } // Bilinearly upscale the images. if(bTwoBitMode) { imgA.BilinearUpscale(3, 2, wrapMode); imgB.BilinearUpscale(3, 2, wrapMode); } else { imgA.BilinearUpscale(2, 2, wrapMode); imgB.BilinearUpscale(2, 2, wrapMode); } if(bDebugImages) { imgA.DebugOutput("RawScaledImgA"); imgB.DebugOutput("RawScaledImgB"); } // Change the bitdepth to full resolution imgA.ExpandTo8888(); imgB.ExpandTo8888(); if(bDebugImages) { imgA.DebugOutput("ScaledImgA"); imgB.DebugOutput("ScaledImgB"); } if(bTwoBitMode) { Decompress2BPP(imgA, imgB, blocks, dcj.OutBuf(), bDebugImages); } else { Decompress4BPP(imgA, imgB, blocks, dcj.OutBuf(), bDebugImages); } }
int mitkHistogramMatchingTest(int /*argc*/, char* /*argv*/[]) { //Create Image out of nowhere mitk::Image::Pointer image; mitk::PixelType pt( mitk::MakeScalarPixelType<int>()); unsigned int dim[]={100,100,20}; std::cout << "Creating image: "; image = mitk::Image::New(); //image->DebugOn(); image->Initialize( mitk::MakeScalarPixelType<int>(), 3, dim); try { mitk::ImageWriteAccessor imgB(image); int* p = (int*) imgB.GetData(); int size = dim[0]*dim[1]*dim[2]; int i; for(i=0; i<size; ++i, ++p) *p=i; std::cout<<"[PASSED]"<<std::endl; } catch(const mitk::Exception&) { // we don't have image access, set test to failed std::cout<<"[FAILED] creation of the image" <<std::endl; return EXIT_FAILURE; } //Create second Image out of nowhere mitk::Image::Pointer image2; mitk::PixelType pt2( mitk::MakeScalarPixelType<int>() ); unsigned int dim2[]={100,100,20}; std::cout << "Creating image: "; image2 = mitk::Image::New(); //image->DebugOn(); image2->Initialize(mitk::MakeScalarPixelType<int>(), 3, dim2); try { mitk::ImageWriteAccessor imgB(image2); int* p2 = (int*) imgB.GetData(); int size2 = dim2[0]*dim2[1]*dim2[2]; int i2; for(i2=0; i2<size2; ++i2, ++p2) *p2=i2; std::cout<<"[PASSED]"<<std::endl; } catch(const mitk::Exception&) { // we don't have image access, set test to failed std::cout<<"[FAILED] creation of the image" <<std::endl; return EXIT_FAILURE; } std::cout << "Constructor: "; mitk::HistogramMatching::Pointer histogramMatching = mitk::HistogramMatching::New(); std::cout<<"[PASSED]"<<std::endl; std::cout << "Set Reference Image: "; histogramMatching->SetReferenceImage(image); std::cout<<"[PASSED]"<<std::endl; std::cout << "Set Moving Image: "; histogramMatching->SetInput(image2); std::cout<<"[PASSED]"<<std::endl; std::cout << "Set number of match points: "; histogramMatching->SetNumberOfMatchPoints(100); std::cout<<"[PASSED]"<<std::endl; std::cout << "Set number of histogram levels: "; histogramMatching->SetNumberOfHistogramLevels(8); std::cout<<"[PASSED]"<<std::endl; std::cout << "Set threshold at mean intensity: "; histogramMatching->SetThresholdAtMeanIntensity(true); std::cout<<"[PASSED]"<<std::endl; std::cout << "Perform histogram matching: "; histogramMatching->Update(); std::cout<<"[PASSED]"<<std::endl; std::cout << "Get the result image: "; mitk::Image::Pointer histimage = histogramMatching->GetOutput(); std::cout<<"[PASSED]"<<std::endl; return EXIT_SUCCESS; }
int mitkSymmetricForcesDemonsRegistrationTest(int /*argc*/, char * /*argv*/ []) { // Create Image out of nowhere mitk::Image::Pointer image; mitk::PixelType pt(mitk::MakeScalarPixelType<int>()); unsigned int dim[] = {100, 100, 20}; std::cout << "Creating image: "; image = mitk::Image::New(); // image->DebugOn(); image->Initialize(mitk::MakeScalarPixelType<int>(), 3, dim); try { mitk::ImageWriteAccessor imgB(image); int *p = (int *)imgB.GetData(); int size = dim[0] * dim[1] * dim[2]; int i; for (i = 0; i < size; ++i, ++p) *p = i; std::cout << "[PASSED]" << std::endl; } catch (mitk::Exception &e) { // we don't have image access, set test to failed std::cout << "[FAILED] creation of the image" << std::endl; return EXIT_FAILURE; } // Create second Image out of nowhere mitk::Image::Pointer image2; mitk::PixelType pt2(mitk::MakeScalarPixelType<int>()); unsigned int dim2[] = {100, 100, 20}; std::cout << "Creating image: "; image2 = mitk::Image::New(); // image->DebugOn(); image2->Initialize(mitk::MakeScalarPixelType<int>(), 3, dim2); try { mitk::ImageWriteAccessor imgB(image2); int *p2 = (int *)imgB.GetData(); int size2 = dim2[0] * dim2[1] * dim2[2]; int i2; for (i2 = 0; i2 < size2; ++i2, ++p2) *p2 = i2; std::cout << "[PASSED]" << std::endl; } catch (mitk::Exception &e) { // we don't have image access, set test to failed std::cout << "[FAILED] creation of the image2" << std::endl; return EXIT_FAILURE; } std::cout << "Constructor: "; mitk::SymmetricForcesDemonsRegistration::Pointer symmetricForcesDemonsRegistration = mitk::SymmetricForcesDemonsRegistration::New(); std::cout << "[PASSED]" << std::endl; std::cout << "Set Reference Image: "; symmetricForcesDemonsRegistration->SetReferenceImage(image); std::cout << "[PASSED]" << std::endl; std::cout << "Set Moving Image: "; symmetricForcesDemonsRegistration->SetInput(image2); std::cout << "[PASSED]" << std::endl; std::cout << "Set number of iterations: "; symmetricForcesDemonsRegistration->SetNumberOfIterations(5); std::cout << "[PASSED]" << std::endl; std::cout << "Set standard deviation: "; symmetricForcesDemonsRegistration->SetStandardDeviation(1.0); std::cout << "[PASSED]" << std::endl; std::cout << "Set save deformation field: "; symmetricForcesDemonsRegistration->SetSaveDeformationField(false); std::cout << "[PASSED]" << std::endl; std::cout << "Set deformation field file name: "; symmetricForcesDemonsRegistration->SetDeformationFieldFileName("TestField.mhd"); std::cout << "[PASSED]" << std::endl; std::cout << "Set save result image: "; symmetricForcesDemonsRegistration->SetSaveResult(false); std::cout << "[PASSED]" << std::endl; std::cout << "Set result image file name: "; symmetricForcesDemonsRegistration->SetResultFileName("TestResult.mhd"); std::cout << "[PASSED]" << std::endl; std::cout << "Perform registration: "; symmetricForcesDemonsRegistration->Update(); std::cout << "[PASSED]" << std::endl; std::cout << "Get the result image: "; mitk::Image::Pointer resultImage = symmetricForcesDemonsRegistration->GetOutput(); std::cout << "[PASSED]" << std::endl; std::cout << "Get the deformation field: "; itk::Image<class itk::Vector<float, 3>, 3>::Pointer deformationField = symmetricForcesDemonsRegistration->GetDeformationField(); std::cout << "[PASSED]" << std::endl; return EXIT_SUCCESS; }