コード例 #1
0
itk::Statistics::ListSample< itk::Vector< double, 1 > >::Pointer pdp::EMClassification::prepareSample(itk::Image<float, 3>::Pointer img, itk::Image<unsigned char, 3>::Pointer mask)
{

	typedef itk::Vector< double, 1 > MeasurementVectorType;
	typedef itk::Statistics::ListSample< MeasurementVectorType > SampleType;
	typedef itk::Image<unsigned char, 3> MaskType;
	typedef itk::Image<float, 3> ImageType;

	SampleType::Pointer sample = SampleType::New();

	typedef itk::ImageRegionConstIterator< ImageType > ImageIteratorType;
	ImageIteratorType imgIt(img, img->GetLargestPossibleRegion());

	typedef itk::ImageRegionConstIterator< MaskType> MaskIteratorType;
	MaskIteratorType maskIt( mask, mask->GetLargestPossibleRegion());

	MeasurementVectorType mv;
	for ( imgIt.GoToBegin(), maskIt.GoToBegin(); !maskIt.IsAtEnd(); ++maskIt, ++imgIt)
	{

		if (maskIt.Get() == 255)
		{
			mv[0] = imgIt.Get();
			sample->PushBack( mv );
		}
	}

	return sample;
}
コード例 #2
0
void SVM__Class::fileIterator(QString filepath, Mat *descriptor, int *counter, char lable){
	QDirIterator imgIt(filepath, QDir::Files);
	QString  absolute_path;
	Size resizeForHog(64, 128);
	

	while (true)
	{
		if (!imgIt.hasNext())
			break;

		imgIt.next();
		QFileInfo fileInfo = imgIt.fileInfo();
		QString box_file_Name = fileInfo.fileName();
		absolute_path = fileInfo.absoluteFilePath();

		//qDebug() << absolute_path;
		std::string path = absolute_path.toStdString();

		Mat image;
		Mat resizedImage;
		Mat resizedGrayImage;

		image = imread(path, CV_LOAD_IMAGE_COLOR);

		cv::resize(image, resizedImage, resizeForHog);
		cv::cvtColor(resizedImage, resizedGrayImage, CV_BGR2GRAY);
		//imshow("Image", resizedGrayImage); 
		HogDescriptor_Class hd;
		Mat mx = hd.generateDescriptorMat(resizedGrayImage);
		(*descriptor).push_back(mx);
		
		if (lable== 'p'){
			training_lable.push_back(positive_f);
		}
		else if (lable == 'n'){
			training_lable.push_back(negative_f);
		}
		else if (lable == 't'){
			testing_result.push_back(positive_f);
		}	

		(*counter)++;
	}
	//__debugbreak();
}
コード例 #3
0
itk::Image<unsigned char, 3>::Pointer pdp::EMClassification::classify(itk::Image<float, 3>::Pointer img, itk::Image<unsigned char, 3>::Pointer mask)
{
	typedef itk::Vector< double, 1 > MeasurementVectorType;
	typedef itk::Image<unsigned char, 3> MaskType;
	typedef itk::Image<float, 3> ImageType;

	typedef itk::ImageRegionConstIterator< ImageType > ImageIteratorType;
	ImageIteratorType imgIt(img, img->GetLargestPossibleRegion());

	typedef itk::ImageRegionConstIterator< MaskType> MaskIteratorType;
	MaskIteratorType maskIt( mask, mask->GetLargestPossibleRegion());

	MaskType::Pointer correctImage = MaskType::New();
	correctImage->CopyInformation(mask);
	MaskType::RegionType outputRegion = mask->GetLargestPossibleRegion();
	correctImage->SetRegions( outputRegion );
	correctImage->Allocate();
	typedef itk::ImageRegionIterator<MaskType> IteratorType;
	IteratorType outputIt( correctImage, outputRegion);

	MeasurementVectorType mv;
	for ( imgIt.GoToBegin(), maskIt.GoToBegin(), outputIt.GoToBegin(); !maskIt.IsAtEnd(); ++maskIt, ++imgIt, ++outputIt)
	{

		if (maskIt.Get() == 255)
		{
			mv[0] = imgIt.Get();
			if (genLabel(mv) == 3)
			{
				outputIt.Set(255);
			}
		}
	}

	return correctImage;
}