Replies: 1 comment
-
It looks funky. Looking at the function bonsai implements: var range = max - min;
var scale = range > 0 ? 1.0 / range : 0;
var shift = range > 0 ? -min : 0;
CV.ConvertScale(input, output, scale, shift);
It seems the easiest way to correct this would be to normalize the shift by the range: var shift = range > 0 ? -min*scale : 0; Here's a temporary fix that you can place in your extensions folder. using OpenCV.Net;
using System;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
namespace Bonsai.Vision
{
/// <summary>
/// Represents an operator that normalizes the range of values for each image
/// in the sequence to be between zero and one.
/// </summary>
[Description("Normalizes the range of values for each image in the sequence to be between zero and one.")]
public class NormalizeFix : Transform<IplImage, IplImage>
{
/// <summary>
/// Normalizes the range of values for each image in an observable sequence
/// to be between zero and one.
/// </summary>
/// <param name="source">The sequence of images to normalize.</param>
/// <returns>
/// The sequence of normalized images.
/// </returns>
public override IObservable<IplImage> Process(IObservable<IplImage> source)
{
return source.Select(input =>
{
var output = new IplImage(input.Size, IplDepth.F32, input.Channels);
double min;
double max;
Point minLoc;
Point maxLoc;
CV.MinMaxLoc(input, out min, out max, out minLoc, out maxLoc);
var range = max - min;
var scale = range > 0 ? 1.0 / range : 0;
var shift = range > 0 ? -min*scale : 0;
CV.ConvertScale(input, output, scale, shift);
return output;
});
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi guys,
I've noticed that the Normalize node not always converts the image pixels to values in the range of [0,1] (or at least the IplImageVisualizer on the Normalize node shows values outside of the [0,1] range, image attached). I don't really understand why since the source code seems to be fine.
I attached a simple Bonsai example to reproduce my observations.
Any help would be welcome. Thanks you in advance.
Cheers,
hugo
NormalizeBug.zip
Beta Was this translation helpful? Give feedback.
All reactions