Example #1
0
ImageEx EstimatorRender::render(const AContainer &group, AProcessWatcher *watcher) const {
	auto planes_amount = group.image(0).size();
	auto min_point = group.minPoint();
	ProgressWrapper( watcher ).setTotal( planes_amount * iterations * group.count() );
	
	auto est = AverageRender().render( group ); //Starting estimate
	est.scaleFactor( upscale_factor );
	auto beta = color::WHITE * this->beta / group.count();
	for( unsigned c=0; c<planes_amount; ++c ){
		for( int i=0; i<iterations; i++ ){
			if( ProgressWrapper(watcher).shouldCancel() )
				return {};
			auto output_copy = est[c];
			
			//Improve estimate
			for( unsigned j=0; j<group.count(); j++, ProgressWrapper( watcher ).add() )
				sign( output_copy, degrade( est[c], {group, j, c} ), group.image(j)[c], group.pos(j)-min_point
					, beta, channelScale(group, j, c)*upscale_factor );
			
			//Regularization
			if( lambda > 0.0 )
				regularize( est[c], output_copy, reg_size, alpha, beta, lambda );
			else
				est[c] = output_copy;
		}
		
		//DEBUG: See how close our model gets to the input data
		for( unsigned j=0; j<group.count(); j++ ){
			save( degrade( est[c], {group, j, c} ), "deg" + QString::number(c) + "-" + QString::number(j) );
			save( group.image(j)[c],                "low" + QString::number(c) + "-" + QString::number(j) );
		}
	}

	return est;
}
Example #2
0
ImageEx PlaneRender::render( const AContainer& aligner, AProcessWatcher* watcher ) const{
	unsigned planes_amount = aligner.image(0).size();
	planes_amount = min( planes_amount, max_planes );
	Progress progress( "PlaneRender", planes_amount, watcher );
	
	//Render all planes
	auto color_space = aligner.image(0).getColorSpace();
	ImageEx img( (planes_amount==1) ? color_space.changed( Transform::GRAY ) : color_space );
	for( unsigned c=0; c<planes_amount; ++c ){
		if( progress.shouldCancel() )
			return {};
		img.addPlane( renderPlane( aligner, c, progress.makeSubtask() ) );
	}
	return img;
}
Example #3
0
ImageEx DiffRender::render( const AContainer& aligner, unsigned max_count, AProcessWatcher* watcher ) const{
	if( max_count > aligner.count() )
		max_count = aligner.count();
	
	//Normal render
	ImageEx avg = SimpleRender( SimpleRender::FOR_MERGING ).render( aligner, max_count );
	
	//Find the smallest shared size
	QSize size = aligner.size().size(); //No image is larger than the final result
	for( unsigned i=0; i<max_count; i++ ){
		size.setWidth( min( (unsigned)size.width(), aligner.image(i).get_width() ) );
		size.setHeight( min( (unsigned)size.height(), aligner.image(i).get_height() ) );
	}
	
	//Create final output image based on the smallest size
	ImageEx img( ImageEx::GRAY );
	img.create( size.width(), size.height() );
	Plane& output = img[0];
	
	if( watcher )
		watcher->setTotal( 1000 );
	
	//Iterate over each pixel in the output image
	for( unsigned iy=0; iy<output.get_height(); iy++ ){
		if( watcher )
			watcher->setCurrent( iy * 1000 / output.get_height() );
		
		color_type* out = output.scan_line( iy );
		for( unsigned ix=0; ix<output.get_width(); ix++ ){
			//Set the pixel to the static difference of all the images until max_count
			StaticDiff diff( aligner, avg, ix, iy );
			
			for( unsigned j=0; j<max_count; j++ )
				diff.add_image( j );
			
			out[ix] = diff.result();
		}
	}
	
	img.apply( &Plane::normalize );
	return img;
}
Example #4
0
Plane PlaneRender::renderPlane( const AContainer& aligner, int plane, AProcessWatcher* watcher ) const{
	auto scale = aligner.image( 0 )[plane].getSize().to<double>() / aligner.image( 0 )[0].getSize().to<double>();
	
	//Create output plane
	Plane out( (Point<>( aligner.size().size ) * scale).round() );
	out.fill( color::BLACK );
	
	//Initialize PlaneItInfos
	vector<PlaneItInfo> info;
	info.emplace_back( out, (aligner.size().pos * scale).round() );
	
	for( auto align : aligner )
		info.emplace_back( const_cast<Plane&>( align.image()[plane] ), (align.pos() * scale).round() );
		//TODO: FIX!!!
	
	//Execute
	MultiPlaneIterator it( info );
	it.data = data();
	it.iterate_all();
	it.for_all_pixels( pixel(), watcher, 1000 * plane );
	
	return out;
}
ImageEx JpegConstrainerRender::render(const AContainer &group, AProcessWatcher *watcher) const {
	//Get the one image we want to constrain
	if( group.count() != 1 )
		throw std::runtime_error( "Can only be used on one image" );
	auto img = group.image(0);
	
	//TODO: Check color types
	
	
	Progress progress( "JpegConstrainerRender", img.size(), watcher );
	progress.loopAll( [&]( int c ){
			//Constrain it to the Coeff
			unsigned change=0;
			img[c] = degrader.planes[c].degradeFromJpegPlane( img[c], jpeg.planes[c], change );
		} );
	
	return img;
}
Example #6
0
ImageEx AverageRender::render( const AContainer& aligner, AProcessWatcher* watcher ) const{
	Timer t( "AverageRender::render()" );
	
	//Abort if no images
	if( aligner.count() == 0 ){
		qWarning( "No images to render!" );
		return ImageEx();
	}
	unsigned planes_amount = for_merging ? 1 : aligner.image(0).size();
	ProgressWrapper( watcher ).setTotal( aligner.count() * planes_amount );
	
	//Determine if we need to care about alpha per plane
	bool use_plane_alpha = false;
	for( unsigned i=0; i<aligner.count(); ++i )
		if( aligner.alpha( i ) || aligner.imageMask( i ) >= 0 ){
			use_plane_alpha = true;
			break;
		}
	//Check for movement in both direction
	auto movement = aligner.hasMovement();
	if( movement.first && movement.second )
		use_plane_alpha = true;
	
	auto color_space = aligner.image(0).getColorSpace();
	ImageEx img( for_merging ? color_space.changed( Transform::GRAY ) : color_space );
	
	AlphaScales masks;
	for( unsigned c=0; c<planes_amount; c++ ){
		auto scale = upscale_chroma ? Point<double>(1,1)
            : aligner.image( 0 )[c].getSize().to<double>() / aligner.image( 0 )[0].getSize().to<double>();
		masks.addScale( aligner, scale );
	}
	
	auto min_point = aligner.minPoint();
	auto full = aligner.size().size;
	for( unsigned c=0; c<planes_amount; c++ ){
		//Determine local size
		auto scale = upscale_chroma ? Point<double>(1,1)
			: aligner.image( 0 )[c].getSize().to<double>() / aligner.image( 0 )[0].getSize().to<double>();
		
		
		//TODO: something is wrong with the rounding, chroma-channels are slightly off
		SumPlane sum( (scale * full).ceil() );
		sum.spacing = spacing;
		sum.offset  = offset;
		
		for( unsigned j=0; j<aligner.count(); j++ ){
			auto& image = aligner.image( j );
			auto pos = (scale * (aligner.pos(j) - min_point)).round();
			auto plane = getScaled( image[c], (scale * image[0].getSize()).round() );
			
			const Plane& alpha_plane = masks.getAlpha( c, aligner.imageMask( j ), aligner.alpha( j ) );
			if( use_plane_alpha && alpha_plane.valid() )
				sum.addAlphaPlane( plane(), alpha_plane, pos );
			else
				sum.addPlane( plane(), pos );
			
			ProgressWrapper( watcher ).add();
		}
		
		img.addPlane( sum.average() );
		
		if( c == 0 && use_plane_alpha )
			img.alpha_plane() = sum.alpha();
			//TODO: what to do about the rest? We should try to fill in the gaps?
	}
	
	return img;
}
Example #7
0
Point<double> channelScale( const AContainer& container, unsigned index, unsigned channel ){
	return container.image(index)[channel].getSize() / container.image(index).getSize().to<double>();
}