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; }
void GenerateData() { mitk::USImage::Pointer ni = this->GetInput(0); mitk::USImage::Pointer result = mitk::USImage::New(); try { mitk::Image::Pointer image = ni.GetPointer(); mitk::ImageWriteAccessor imgA(image, image->GetVolumeData(0)); result->Initialize(image); result->SetImportVolume(imgA.GetData()); mitk::USImageMetadata::Pointer meta = ni->GetMetadata(); meta->SetDeviceComment("Test"); result->SetMetadata(meta); SetNthOutput(0, result); } catch(mitk::Exception& e) { std::stringstream msg; msg << "Cannot open image for reading: " << e.GetDescription(); MITK_TEST_FAILED_MSG(<<msg.str()); } };
/** * 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); } }
void ImageProcessing::getDisparity() { int windowSize = 9; int DSR = 20; //char *leftImgPath, *rightImgPath; //cout<<"Enter full path of Left image "; //cin>>leftImgPath; //cout<<"Enter full path of Left image "; //cin>>rightImgPath; IplImage *LeftinputImage = cvLoadImage("../outputs/raw/left-0.pgm", 0); IplImage *RightinputImage = cvLoadImage("../outputs/raw/right-0.pgm", 0); // int width = LeftinputImage->width; // int height = LeftinputImage->height; /****************8U to 32F**********************/ IplImage *LeftinputImage32 = cvCreateImage(cvSize(LeftinputImage->width, LeftinputImage->height), 32, 1); //IPL_DEPTH_32F IplImage *RightinputImage32 = cvCreateImage(cvSize(LeftinputImage->width, LeftinputImage->height), 32, 1); cvConvertScale(LeftinputImage, LeftinputImage32, 1 / 255.); cvConvertScale(RightinputImage, RightinputImage32, 1 / 255.); int offset = floor((double) windowSize / 2); int height = LeftinputImage32->height; int width = LeftinputImage32->width; double *localNCC = new double[DSR]; int x = 0, y = 0, d = 0, m = 0; int N = windowSize; IplImage *leftWinImg = cvCreateImage(cvSize(N, N), 32, 1); //mySubImage(LeftinputImage32,cvRect(0,0,N,N)); IplImage *rightWinImg = cvCreateImage(cvSize(N, N), 32, 1); //mySubImage(RightinputImage32,cvRect(0,0,N,N)); IplImage *disparity = cvCreateImage(cvSize(width, height), 8, 1); //or IPL_DEPTH_8U BwImage imgA(disparity); for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { imgA[y][x] = 0; } } CvScalar s1; CvScalar s2; for (y = 0; y < height - N; y++) { //height-N for (x = 0; x < width - N; x++) { //width-N //getWindow(i,j,leftim,wl,N); cvSetImageROI(LeftinputImage32, cvRect(x, y, N, N)); s1 = cvAvg(LeftinputImage32, NULL); cvSubS(LeftinputImage32, s1, leftWinImg, NULL); //zero-means cvNormalize(leftWinImg, leftWinImg, 1, 0, CV_L2, NULL); d = 0; //initialise localNCC for (m = 0; m < DSR; m++) { localNCC[m] = 0; } do { if (x - d >= 0) { cvSetImageROI(RightinputImage32, cvRect(x - d, y, N, N)); s2 = cvAvg(RightinputImage32, NULL); cvSubS(RightinputImage32, s2, rightWinImg, NULL); //zero-means cvNormalize(rightWinImg, rightWinImg, 1, 0, CV_L2, NULL); } else { break; } localNCC[d] = cvDotProduct(leftWinImg, rightWinImg); cvResetImageROI(RightinputImage32); d++; } while (d <= DSR); //to find the best d and store imgA[y + offset][x + offset] = getMaxMin(localNCC, DSR, 1) *16; cvResetImageROI(LeftinputImage32); } //x if (y % 10 == 0) cout << "row=" << y << " of " << height << endl; } //y cvReleaseImage(&leftWinImg); cvReleaseImage(&rightWinImg); cvSaveImage("disparity.pgm", disparity); waitHere(); //cv::imwrite("disparity.pgm",&disparity); cout << "Displaying Disparity image" << endl; // cvShowImage( "Disparity", disparity); //cv::waitKey(0); //return disparity; }