C
C#15mo ago
Whiteboy

❔ Check pixel intensity along a line in image

so i made this funcion that should do it but i get this weird error
private void DrawProfileLane()
{
// load image and convert to grayscale
Image<Bgr, byte> image = new Image<Bgr, byte>("path/to/image.jpg");
Image<Gray, byte> grayImage = image.Convert<Gray, byte>();

// check that both points are defined
if (_firstPoint == null || _secondPoint == null)
{
return;
}

// define line between two points
Point firstPoint = _firstPoint.Value;
Point secondPoint = _secondPoint.Value;
LineSegment2D line = new LineSegment2D(firstPoint, secondPoint);
float dx = line.Direction.X;
float dy = line.Direction.Y;
double length = line.Length;

// get pixel intensity values along the line using a parallel for loop
int[] intensities = new int[(int)length];
Parallel.For(0, (int)length, i =>
{
Point pointOnLine = new Point((int)(firstPoint.X + i * dx / length), (int)(firstPoint.Y + i * dy / length));
intensities[i] = grayImage.Data[(int) pointOnLine.Y, (int) pointOnLine.X, 0];
});

// create plot and add data
double[] intensitiesDouble = intensities.Select(x => (double)x).ToArray();
WpfPlot plot = new WpfPlot();
plot.Plot.AddSignal(intensitiesDouble);

// create and show window
ProfileLaneWindow profileLaneWindow = new ProfileLaneWindow
{
Title = $"Profile Lane Plot of {Title}",
ProfileLanePlot = plot,
};
profileLaneWindow.Show();
}
private void DrawProfileLane()
{
// load image and convert to grayscale
Image<Bgr, byte> image = new Image<Bgr, byte>("path/to/image.jpg");
Image<Gray, byte> grayImage = image.Convert<Gray, byte>();

// check that both points are defined
if (_firstPoint == null || _secondPoint == null)
{
return;
}

// define line between two points
Point firstPoint = _firstPoint.Value;
Point secondPoint = _secondPoint.Value;
LineSegment2D line = new LineSegment2D(firstPoint, secondPoint);
float dx = line.Direction.X;
float dy = line.Direction.Y;
double length = line.Length;

// get pixel intensity values along the line using a parallel for loop
int[] intensities = new int[(int)length];
Parallel.For(0, (int)length, i =>
{
Point pointOnLine = new Point((int)(firstPoint.X + i * dx / length), (int)(firstPoint.Y + i * dy / length));
intensities[i] = grayImage.Data[(int) pointOnLine.Y, (int) pointOnLine.X, 0];
});

// create plot and add data
double[] intensitiesDouble = intensities.Select(x => (double)x).ToArray();
WpfPlot plot = new WpfPlot();
plot.Plot.AddSignal(intensitiesDouble);

// create and show window
ProfileLaneWindow profileLaneWindow = new ProfileLaneWindow
{
Title = $"Profile Lane Plot of {Title}",
ProfileLanePlot = plot,
};
profileLaneWindow.Show();
}
Argument type 'System.Windows.Point' is not assignable to parameter type 'System.Drawing.Point' here:
LineSegment2D line = new LineSegment2D(firstPoint, secondPoint);
LineSegment2D line = new LineSegment2D(firstPoint, secondPoint);
at "firstPoint"
2 Replies
Whiteboy
Whiteboy15mo ago
fixed it like this
LineSegment2D line = new LineSegment2D(new System.Drawing.Point((int)firstPoint.X, (int)firstPoint.Y), new System.Drawing.Point((int)secondPoint.X, (int)secondPoint.Y));
LineSegment2D line = new LineSegment2D(new System.Drawing.Point((int)firstPoint.X, (int)firstPoint.Y), new System.Drawing.Point((int)secondPoint.X, (int)secondPoint.Y));
Accord
Accord15mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.