void CurveletGUI::ProcessFiles() { if (!this->InputFileList.isEmpty()) { float sigma = (float) this->SigmaValue->value(); QProgressDialog progress("Converting Images", "Abort", 0, this->InputFileList.size(), this); progress.setWindowModality(Qt::WindowModal); for (int i = 0; i < this->InputFileList.size(); i++) { progress.setValue(i); if (progress.wasCanceled()) { break; } QString outputname = this->InputFileList[i]; outputname.insert(outputname.size() -4, QString("_cv")); InputReaderType::Pointer reader = InputReaderType::New(); OutputWriterType::Pointer writer = OutputWriterType::New(); reader->SetFileName(this->InputFileList[i].toStdString().c_str()); reader->Update(); Curvelet curvletfilter = Curvelet(); curvletfilter.SetSigma(sigma); TiffImageType::Pointer outputim = curvletfilter.RunOnInputImage(reader->GetOutput()); std::cout<< "writing "<<outputname.toStdString().c_str() << std::endl; writer->SetInput(outputim); writer->SetFileName(outputname.toStdString().c_str()); writer->Update(); } progress.setValue(this->InputFileList.size()); }//end file list empty }
int main(int argc, char *argv[]) { if (argc < 3) { std::cerr << "Usage: " << "<input filename> " << "<output filename> " << std::endl; return 1; } typedef unsigned short InputPixelType; typedef unsigned char OutputPixelType; const unsigned Dimension = 3; typedef itk::Image<InputPixelType, Dimension> InputImageType; typedef itk::Image<OutputPixelType, Dimension> OutputImageType; typedef itk::ImageFileReader<InputImageType> InputReaderType; typedef itk::ImageFileWriter<OutputImageType> OutputWriterType; InputReaderType::Pointer reader = InputReaderType::New(); OutputWriterType::Pointer writer = OutputWriterType::New(); const char* outputFilename = argv[2]; const char* inputFilename = argv[1]; reader->SetFileName(inputFilename); try { reader->Update(); } catch (itk::ExceptionObject &err) { std::cerr << "Error in reader: " << err << std::endl; return -1; } typedef itk::RescaleIntensityImageFilter<InputImageType, OutputImageType> RescaleFilterType; RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New(); rescaleFilter->SetInput(reader->GetOutput()); rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); try { rescaleFilter->Update(); } catch (itk::ExceptionObject &err) { std::cerr << "Error in rescaleFilter: " << err << std::endl; return -1; } writer->SetInput(rescaleFilter->GetOutput()); writer->SetFileName(outputFilename); try { writer->Update(); } catch (itk::ExceptionObject &err) { std::cerr << "Error in writer: " << err << std::endl; return -1; } writer->Update(); }
void ImageFileManger::ProcessFiles() { if (!this->InputFileList.isEmpty()) { QDir directory(this->imageDir); for (int k = 0; k < this->outputDirectories.size(); k++) { directory.mkdir(this->outputDirectories[k]); } QProgressDialog progress("Converting Images", "Abort", 0, this->InputFileList.size(), this); progress.setWindowModality(Qt::WindowModal); for (int i = 0; i < this->InputFileList.size(); i++) { progress.setValue(i); if (progress.wasCanceled()) { break; } QString currentDir; currentDir.clear(); QString tempname = QFileInfo(this->InputFileList[i]).fileName(); for (int j = 0; j < this->outputDirectories.size(); j++) { if (tempname.contains(this->outputDirectories.at(j), Qt::CaseInsensitive)) { currentDir = this->outputDirectories.at(j); }//end search } if (currentDir.isEmpty()) { continue; } tempname.replace(" ", "_"); tempname.prepend("8Bit"); QString outputFilename = QString(this->imageDir +"/"+ currentDir +"/"+tempname); InputReaderType::Pointer reader = InputReaderType::New(); OutputWriterType::Pointer writer = OutputWriterType::New(); reader->SetFileName(this->InputFileList[i].toStdString().c_str()); //16 to 8 bit conversion RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New(); rescaleFilter->SetInput(reader->GetOutput()); rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); rescaleFilter->Update(); preprocessdialog->SetImage( rescaleFilter->GetOutput() ); writer->SetFileName(outputFilename.toStdString().c_str()); try { preprocessdialog->Process(); writer->SetInput(preprocessdialog->GetImage()); writer->Update(); } catch(itk::ExceptionObject & e) { std::cerr << "Exception in ITK Pipeline: " << e << std::endl; continue; } } progress.setValue(this->InputFileList.size()); } }