int main (int argc, char ** argv) { std::ifstream input ("converted.txt"); std::string filename; std::vector<std::string> filenames; std::vector<bool> depths; std::vector<std::pair<std::string, std::string> > pairs; while (input >> filename) { filenames.push_back (filename); depths.push_back (filename.find (".jpg") == std::string::npos); } input.close(); for (int i = 0; i < filenames.size() - 1; ++i) { if (depths[i] != depths[i + 1]) { std::string depth = depths[i] ? filenames[i] : filenames[ i + 1]; std::string rgb = depths [i] ? filenames[i + 1]: filenames[i]; pairs.push_back(make_pair(rgb, depth)); ++i; } } for (int i = 0; i < pairs.size(); ++i) { std::stringstream ss1; ss1 << "converted/" << pairs[i].first; std::stringstream ss1_new; ss1_new << "images/" << i << ".jpg"; std::ifstream inputRGB (ss1.str().c_str()); std::ofstream outputRGB (ss1_new.str().c_str()); outputRGB << inputRGB.rdbuf(); outputRGB.close(); inputRGB.close(); std::stringstream ss2; ss2 << "converted/" << pairs[i].second; std::stringstream ss2_new; ss2_new << "images/" << i << ".txt"; std::ifstream inputDepth (ss2.str().c_str()); std::ofstream outputDepth (ss2_new.str().c_str()); outputDepth << inputDepth.rdbuf(); outputDepth.close(); inputDepth.close(); std::cout << 100*i/pairs.size() << "% complete" << std::endl; } return 0; }
void transformsChain::runTransform( const ptr<image>& inputImage, std::uint32_t inputTopLeftX, std::uint32_t inputTopLeftY, std::uint32_t inputWidth, std::uint32_t inputHeight, const ptr<image>& outputImage, std::uint32_t outputTopLeftX, std::uint32_t outputTopLeftY) { if(isEmpty()) { ptr<transformHighBit> highBit(new transformHighBit); highBit->runTransform(inputImage, inputTopLeftX, inputTopLeftY, inputWidth, inputHeight, outputImage, outputTopLeftX, outputTopLeftY); return; } if(m_transformsList.size() == 1) { m_transformsList.front()->runTransform(inputImage, inputTopLeftX, inputTopLeftY, inputWidth, inputHeight, outputImage, outputTopLeftX, outputTopLeftY); return; } // Get the position of the last transform /////////////////////////////////////////////////////////// tTransformsList::iterator lastTransform(m_transformsList.end()); --lastTransform; std::wstring inputColorSpace(inputImage->getColorSpace()); image::bitDepth inputDepth(inputImage->getDepth()); std::uint32_t inputHighBit(inputImage->getHighBit()); std::wstring outputColorSpace(outputImage->getColorSpace()); image::bitDepth outputDepth(outputImage->getDepth()); std::uint32_t outputHighBit(outputImage->getHighBit()); std::uint32_t allocateRows = 65536 / inputWidth; if(allocateRows < 1) { allocateRows = 1; } if(allocateRows > inputHeight) { allocateRows = inputHeight; } // Allocate temporary images /////////////////////////////////////////////////////////// if( m_inputWidth != inputWidth || m_inputHeight != inputHeight || m_inputColorSpace != inputColorSpace || m_inputDepth != inputDepth || m_inputHighBit != inputHighBit || m_outputColorSpace != outputColorSpace || m_outputDepth != outputDepth || m_outputHighBit != outputHighBit) { m_inputWidth = inputWidth; m_inputHeight = inputHeight; m_inputColorSpace = inputColorSpace; m_inputDepth = inputDepth; m_inputHighBit = inputHighBit; m_outputColorSpace = outputColorSpace; m_outputDepth = outputDepth; m_outputHighBit = outputHighBit; m_temporaryImages.clear(); tTransformsList::iterator scanTransforms(m_transformsList.begin()); m_temporaryImages.push_back((*scanTransforms)->allocateOutputImage(inputImage, inputWidth, allocateRows)); while(++scanTransforms != lastTransform) { m_temporaryImages.push_back((*scanTransforms)->allocateOutputImage(m_temporaryImages.back(), inputWidth, allocateRows)); } } // Run all the transforms. Split the images into several // parts /////////////////////////////////////////////////////////// while(inputHeight != 0) { std::uint32_t rows = allocateRows; if(rows > inputHeight) { rows = inputHeight; } inputHeight -= rows; tTransformsList::iterator scanTransforms(m_transformsList.begin()); tTemporaryImagesList::iterator scanTemporaryImages(m_temporaryImages.begin()); (*scanTransforms)->runTransform(inputImage, inputTopLeftX, inputTopLeftY, inputWidth, rows, *scanTemporaryImages, 0, 0); inputTopLeftY += rows; while(++scanTransforms != lastTransform) { ptr<image> temporaryInput(*(scanTemporaryImages++)); ptr<image> temporaryOutput(*scanTemporaryImages); (*scanTransforms)->runTransform(temporaryInput, 0, 0, inputWidth, rows, temporaryOutput, 0, 0); } m_transformsList.back()->runTransform(*scanTemporaryImages, 0, 0, inputWidth, rows, outputImage, outputTopLeftX, outputTopLeftY); outputTopLeftY += rows; } }
ptr<image> modalityVOILUT::allocateOutputImage(ptr<image> pInputImage, std::uint32_t width, std::uint32_t height) { if(isEmpty()) { ptr<image> newImage(new image()); newImage->create(width, height, pInputImage->getDepth(), pInputImage->getColorSpace(), pInputImage->getHighBit()); return newImage; } // LUT /////////////////////////////////////////////////////////// if(m_voiLut != 0 && m_voiLut->getSize() != 0 && m_voiLut->checkValidDataRange()) { std::uint8_t bits(m_voiLut->getBits()); // Look for negative outputs bool bNegative(false); for(std::int32_t index(m_voiLut->getFirstMapped()), size(m_voiLut->getSize()); !bNegative && size != 0; --size, ++index) { bNegative = (m_voiLut->mappedValue(index) < 0); } image::bitDepth depth; if(bNegative) { if(bits > 16) { depth = image::depthS32; } else if(bits > 8) { depth = image::depthS16; } else { depth = image::depthS8; } } else { if(bits > 16) { depth = image::depthU32; } else if(bits > 8) { depth = image::depthU16; } else { depth = image::depthU8; } } ptr<image> returnImage(new image); returnImage->create(width, height, depth, pInputImage->getColorSpace(), bits - 1); return returnImage; } // Rescale /////////////////////////////////////////////////////////// if(m_rescaleSlope == 0) { ptr<image> returnImage(new image); returnImage->create(width, height, pInputImage->getDepth(), pInputImage->getColorSpace(), pInputImage->getHighBit()); return returnImage; } image::bitDepth inputDepth(pInputImage->getDepth()); std::uint32_t highBit(pInputImage->getHighBit()); std::int32_t value0 = 0; std::int32_t value1 = ((std::int32_t)1 << (highBit + 1)) - 1; if(inputDepth == image::depthS16 || inputDepth == image::depthS8) { value0 = ((std::int32_t)(-1) << highBit); value1 = ((std::int32_t)1 << highBit); } std::int32_t finalValue0((std::int32_t) ((double)value0 * m_rescaleSlope + m_rescaleIntercept + 0.5) ); std::int32_t finalValue1((std::int32_t) ((double)value1 * m_rescaleSlope + m_rescaleIntercept + 0.5) ); std::int32_t minValue, maxValue; if(finalValue0 < finalValue1) { minValue = finalValue0; maxValue = finalValue1; } else { minValue = finalValue1; maxValue = finalValue0; } ptr<image> returnImage(new image); if(minValue >= 0 && maxValue <= 255) { returnImage->create(width, height, image::depthU8, pInputImage->getColorSpace(), 7); return returnImage; } if(minValue >= -128 && maxValue <= 127) { returnImage->create(width, height, image::depthS8, pInputImage->getColorSpace(), 7); return returnImage; } if(minValue >= 0 && maxValue <= 65535) { returnImage->create(width, height, image::depthU16, pInputImage->getColorSpace(), 15); return returnImage; } if(minValue >= -32768 && maxValue <= 32767) { returnImage->create(width, height, image::depthS16, pInputImage->getColorSpace(), 15); return returnImage; } returnImage->create(width, height, image::depthS32, pInputImage->getColorSpace(), 31); return returnImage; }