Making hue work again
This commit is contained in:
parent
215b7140fb
commit
b55438171a
3 changed files with 86 additions and 37 deletions
|
|
@ -41,7 +41,6 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
public class Histogram
|
||||
{
|
||||
private ImageBuffer _histogramRawCache = new ImageBuffer(256, 100);
|
||||
private ThemeConfig theme;
|
||||
|
||||
public double RangeStart { get; set; } = 0;
|
||||
|
||||
|
|
@ -120,13 +119,19 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
alphaImage.MarkImageChanged();
|
||||
}
|
||||
|
||||
public void BuildHistogramFromImage(ImageBuffer image)
|
||||
public void BuildHistogramFromImage(ImageBuffer image, ImageToPathObject3D_2.AnalysisTypes analysisType)
|
||||
{
|
||||
// build the histogram cache
|
||||
_histogramRawCache = new ImageBuffer(256, 100);
|
||||
var height = (int)(100 * GuiWidget.DeviceScale);
|
||||
_histogramRawCache = new ImageBuffer(256, height);
|
||||
var counts = new int[_histogramRawCache.Width];
|
||||
IThresholdFunction function = new MapOnMaxIntensity(RangeStart, RangeEnd);
|
||||
function = new HueThresholdFunction(RangeStart, RangeEnd);
|
||||
var bottom = 0;
|
||||
if (analysisType == ImageToPathObject3D_2.AnalysisTypes.Colors)
|
||||
{
|
||||
function = new HueThresholdFunction(RangeStart, RangeEnd);
|
||||
bottom = (int)(10 * GuiWidget.DeviceScale);
|
||||
}
|
||||
|
||||
byte[] buffer = image.GetBuffer();
|
||||
for (int y = 0; y < image.Height; y++)
|
||||
|
|
@ -144,22 +149,29 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
double max = counts.Select((value, index) => new { value, index })
|
||||
.OrderByDescending(vi => vi.value)
|
||||
.First().value;
|
||||
var graphics2D2 = _histogramRawCache.NewGraphics2D();
|
||||
graphics2D2.Clear(ApplicationController.Instance.Theme.SlightShade);
|
||||
var graphics = _histogramRawCache.NewGraphics2D();
|
||||
var theme = ApplicationController.Instance.Theme;
|
||||
graphics.Clear(theme.SlightShade);
|
||||
|
||||
var graphShape = new VertexStorage();
|
||||
graphShape.MoveTo(0, 0);
|
||||
var graphHeight = height - bottom;
|
||||
graphShape.MoveTo(0, bottom);
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
graphShape.LineTo(i, Easing.Exponential.Out(counts[i] / max) * _histogramRawCache.Height);
|
||||
graphShape.LineTo(i, bottom + Easing.Exponential.Out(counts[i] / max) * graphHeight);
|
||||
}
|
||||
graphShape.LineTo(image.Width, bottom);
|
||||
graphics.Render(graphShape, 0, 0, theme.TextColor);
|
||||
|
||||
for(int i=0; i<256; i++)
|
||||
{
|
||||
var hue = ColorF.FromHSL(i / 255.0, 1, .49).ToColor();
|
||||
graphics.Line(i, 0, i, bottom, hue);
|
||||
}
|
||||
graphShape.LineTo(image.Width, 0);
|
||||
graphics2D2.Render(graphShape, 0, 0, theme.TextColor);
|
||||
}
|
||||
|
||||
public GuiWidget NewEditWidget(ThemeConfig theme)
|
||||
{
|
||||
this.theme = theme;
|
||||
var histogramWidget = new GuiWidget()
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
Name = "Image to Path".Localize();
|
||||
}
|
||||
|
||||
public enum FeatureDetectors
|
||||
public enum AnalysisTypes
|
||||
{
|
||||
Transparency,
|
||||
Colors,
|
||||
|
|
@ -80,24 +80,24 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
&& SourceImage != null)
|
||||
{
|
||||
_image = new ImageBuffer(SourceImage);
|
||||
IntensityHistogram.BuildHistogramFromImage(SourceImage);
|
||||
IntensityHistogram.RangeChanged += (s, e) =>
|
||||
Histogram.BuildHistogramFromImage(SourceImage, AnalysisType);
|
||||
Histogram.RangeChanged += (s, e) =>
|
||||
{
|
||||
IntensityHistogram.RebuildAlphaImage(SourceImage, _image);
|
||||
Histogram.RebuildAlphaImage(SourceImage, _image);
|
||||
};
|
||||
|
||||
IntensityHistogram.EditComplete += (s, e) =>
|
||||
Histogram.EditComplete += (s, e) =>
|
||||
{
|
||||
this.Invalidate(InvalidateType.Properties);
|
||||
};
|
||||
|
||||
switch (FeatureDetector)
|
||||
switch (AnalysisType)
|
||||
{
|
||||
case FeatureDetectors.Intensity:
|
||||
IntensityHistogram.RebuildAlphaImage(SourceImage, _image);
|
||||
case AnalysisTypes.Intensity:
|
||||
Histogram.RebuildAlphaImage(SourceImage, _image);
|
||||
break;
|
||||
|
||||
case FeatureDetectors.Transparency:
|
||||
case AnalysisTypes.Transparency:
|
||||
_image.CopyFrom(SourceImage);
|
||||
break;
|
||||
}
|
||||
|
|
@ -112,9 +112,9 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
}
|
||||
|
||||
|
||||
private FeatureDetectors _featureDetector = FeatureDetectors.Intensity;
|
||||
private AnalysisTypes _featureDetector = AnalysisTypes.Intensity;
|
||||
[EnumDisplay(Mode = EnumDisplayAttribute.PresentationMode.Tabs)]
|
||||
public FeatureDetectors FeatureDetector
|
||||
public AnalysisTypes AnalysisType
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
@ -126,15 +126,25 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
if (_featureDetector != value)
|
||||
{
|
||||
_featureDetector = value;
|
||||
switch (FeatureDetector)
|
||||
var sourceImage = SourceImage;
|
||||
if (sourceImage != null)
|
||||
{
|
||||
case FeatureDetectors.Intensity:
|
||||
IntensityHistogram.RebuildAlphaImage(SourceImage, Image);
|
||||
break;
|
||||
switch (AnalysisType)
|
||||
{
|
||||
case AnalysisTypes.Intensity:
|
||||
Histogram.BuildHistogramFromImage(sourceImage, AnalysisType);
|
||||
Histogram.RebuildAlphaImage(sourceImage, Image);
|
||||
break;
|
||||
|
||||
case FeatureDetectors.Transparency:
|
||||
Image?.CopyFrom(SourceImage);
|
||||
break;
|
||||
case AnalysisTypes.Colors:
|
||||
Histogram.BuildHistogramFromImage(sourceImage, AnalysisType);
|
||||
Histogram.RebuildAlphaImage(sourceImage, Image);
|
||||
break;
|
||||
|
||||
case AnalysisTypes.Transparency:
|
||||
Image?.CopyFrom(sourceImage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -148,7 +158,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
[JsonIgnore]
|
||||
private ImageBuffer SourceImage => ((IImageProvider)this.Descendants().Where(i => i is IImageProvider).FirstOrDefault())?.Image;
|
||||
|
||||
public Histogram IntensityHistogram { get; set; } = new Histogram();
|
||||
public Histogram Histogram { get; set; } = new Histogram();
|
||||
|
||||
public IVertexSource VertexSource { get; set; } = new VertexStorage();
|
||||
|
||||
|
|
@ -236,8 +246,8 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
&& invalidateArgs.Source != this
|
||||
&& !RebuildLocked)
|
||||
{
|
||||
IntensityHistogram.BuildHistogramFromImage(SourceImage);
|
||||
IntensityHistogram.RebuildAlphaImage(SourceImage, _image);
|
||||
Histogram.BuildHistogramFromImage(SourceImage, AnalysisType);
|
||||
Histogram.RebuildAlphaImage(SourceImage, _image);
|
||||
await Rebuild();
|
||||
}
|
||||
else if ((invalidateArgs.InvalidateType.HasFlag(InvalidateType.Properties) && invalidateArgs.Source == this))
|
||||
|
|
@ -264,9 +274,9 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
(reporter, cancellationToken) =>
|
||||
{
|
||||
var progressStatus = new ProgressStatus();
|
||||
switch (FeatureDetector)
|
||||
switch (AnalysisType)
|
||||
{
|
||||
case FeatureDetectors.Transparency:
|
||||
case AnalysisTypes.Transparency:
|
||||
this.GenerateMarchingSquaresAndLines(
|
||||
(progress0to1, status) =>
|
||||
{
|
||||
|
|
@ -278,7 +288,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
new AlphaFunction());
|
||||
break;
|
||||
|
||||
case FeatureDetectors.Intensity:
|
||||
case AnalysisTypes.Intensity:
|
||||
this.GenerateMarchingSquaresAndLines(
|
||||
(progress0to1, status) =>
|
||||
{
|
||||
|
|
@ -303,8 +313,8 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
public void UpdateControls(PublicPropertyChange change)
|
||||
{
|
||||
change.SetRowVisible(nameof(IntensityHistogram), () => FeatureDetector == FeatureDetectors.Intensity);
|
||||
change.SetRowVisible(nameof(TransparencyMessage), () => FeatureDetector == FeatureDetectors.Transparency);
|
||||
change.SetRowVisible(nameof(Histogram), () => AnalysisType != AnalysisTypes.Transparency);
|
||||
change.SetRowVisible(nameof(TransparencyMessage), () => AnalysisType == AnalysisTypes.Transparency);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue