static dict loadEntry( std::string name ) {
	std::string sets[] = {"train","val","test"};
	std::string im_dir = berkeley_dir+"/images/";
	std::string gt_dir = berkeley_dir+"/groundTruth/";
	std::string cs_dir = berkeley_dir+"/cache/";
	mkdir( cs_dir );
	for (std::string s: sets)
		mkdir( cs_dir+s );
	
	dict r;
	for (std::string s: sets) {
		std::string im_name = s+"/"+name+".jpg";
		std::shared_ptr<Image8u> im = imreadShared( im_dir + "/" + im_name );
		if( im && !im->empty() ) {
			std::string sname = s+"/"+name+".png", bname = s+"/"+name+"_bnd.png", mname = s+"/"+name+".mat";
			
			std::vector<RMatrixXs> seg;
			{
				std::vector<RMatrixXu8> tmp = readAPNG( cs_dir + "/" + sname );
				for( auto i: tmp )
					seg.push_back( i.cast<short>() );
			}
			std::vector<RMatrixXb> bnd;
			{
				std::vector<RMatrixXu8> tmp = readAPNG( cs_dir + "/" + bname );
				for( auto i: tmp )
					bnd.push_back( i.cast<bool>() );
			}
			
			if( seg.size()==0 || bnd.size()==0 ) {
				std::tie(seg,bnd) = readMat( gt_dir + "/" + mname );
				{
					std::vector<RMatrixXu8> tmp;
					for( auto i: seg )
						tmp.push_back( i.cast<uint8_t>() );
					writeAPNG( cs_dir + "/" + sname, tmp );
				}
				{
					std::vector<RMatrixXu8> tmp;
					for( auto i: bnd )
						tmp.push_back( i.cast<uint8_t>() );
					writeAPNG( cs_dir + "/" + bname, tmp );
				}
			}
			if( bnd.size() && seg.size() ) {
				std::vector<RMatrixXb> bnd_b;
				for( auto i: bnd )
					bnd_b.push_back( i.cast<bool>() );
				r["image"] = im;
				r["segmentation"] = seg;
				r["boundary"] = bnd_b;
				r["name"] = name;
				return r;
			}
		}
	}
	return r;
}
Example #2
0
static dict loadEntry( std::string name ) {
	std::string sets[] = {"train","val","test"};
	std::string im_dir = berkeley_dir+"/images/";
	std::string gt_dir = berkeley_dir+"/groundTruth/";
	std::string cs_dir = berkeley_dir+"/cache/";
	mkdir( cs_dir );
	for (std::string s: sets)
		mkdir( cs_dir+s );
	
	dict r;
	for (std::string s: sets) {
		std::string im_name = s+"/"+name+".jpg";
		std::shared_ptr<Image8u> im = imreadShared( im_dir + "/" + im_name );
		if( im && !im->empty() ) {
			std::string sname = s+"/"+name+".png", bname = s+"/"+name+"_bnd.png", mname = s+"/"+name+".mat";
			
			np::ndarray seg = readAPNG( cs_dir + "/" + sname );
			np::ndarray bnd = readAPNG( cs_dir + "/" + bname );
			
			if( !seg.get_nd() ) {
				seg = sgread( gt_dir + "/" + mname );
				writeAPNG( cs_dir + "/" + sname, seg );
			}
			if( !bnd.get_nd() ) {
				bnd = bnread( gt_dir + "/" + mname );
				writeAPNG( cs_dir + "/" + bname, bnd );
			}
			if( bnd.get_nd() && seg.get_nd() ) {
				r["image"] = im;
				r["segmentation"] = seg;
				r["boundary"] = bnd;
				r["name"] = name;
				return r;
			}
		}
	}
	return r;
}