Skip to content

Commit

Permalink
Kinda fixed the lowpass equalize, but I think the algorithm needs som…
Browse files Browse the repository at this point in the history
…e idea to really improve it.
  • Loading branch information
Hans Doof committed Dec 19, 2020
1 parent a36cd68 commit 3ba70c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
3 changes: 3 additions & 0 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
<RadioButton x:Name="lowPassMatchNone_radio" Checked="LowPassMatch_radio_Checked" IsChecked="True">None</RadioButton>
<RadioButton x:Name="lowPassMatchReferenceToSource_radio" Checked="LowPassMatch_radio_Checked">Reference to test (recommended)</RadioButton>
</WrapPanel>
<WrapPanel>
<Label>Blur radius</Label>
<TextBox MinWidth="50" x:Name="lowpassEqualizeBlurRadius_Text" TextChanged="LowpassEqualizeBlurRadius_Text_TextChanged">200</TextBox></WrapPanel>
<Border BorderThickness="1" BorderBrush="LightGray" Margin="5"></Border>


Expand Down
35 changes: 27 additions & 8 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,19 @@ public MainWindow()

private void readGUISettings()
{


try {


lowPassEqualizeBlurRadius = float.Parse(lowpassEqualizeBlurRadius_Text.Text);
}
catch (Exception e) { //fuck, it's just called too early and the objects dont exist. whatever.
}
try {




if (lowPassMatchNone_radio.IsChecked == true)
{
Expand Down Expand Up @@ -106,6 +115,10 @@ enum AggregateColorSpace { SRGB, SRGBLINEAR, XYZ, CIELAB };
enum LowPassMatching { NONE, REFERENCETOTEST, TESTTOREFERENCE};
LowPassMatching lowPassMatching = LowPassMatching.NONE;

float lowPassEqualizeBlurRadius = 200f;



const int R = 0;
const int G = 1;
const int B = 2;
Expand Down Expand Up @@ -328,8 +341,8 @@ private void DoColorMatch_Worker(IProgress<MatchReport> progress,Bitmap testImag

int resX = testImage.Width, resY = testImage.Height;

byte[,,] testImgData = new byte[resX, resY, 3];
byte[,,] refImgData = new byte[resX, resY, 3];
float[,,] testImgData = new float[resX, resY, 3];
float[,,] refImgData = new float[resX, resY, 3];

// 3D Histogram.
// Each possible color in a 256x256x256 RGB colorspace has one entry.
Expand Down Expand Up @@ -366,7 +379,7 @@ public struct Color
if (lowPassMatching == LowPassMatching.REFERENCETOTEST)
{

float blurRadius = 50;
float blurRadius = lowPassEqualizeBlurRadius;
int blurSizeX = (int)(resX / blurRadius);
int blurSizeY = (int)(resY / blurRadius);

Expand All @@ -378,8 +391,8 @@ public struct Color
progress.Report(new MatchReport("Blurring reference image...."));
ByteImage referenceBitmapBlurred = Helpers.BlurImage(referenceBitmap, 50);*/

Helpers.ByteArrayToBitmap(testBitmapBlurred).Save("test1.png");
Helpers.ByteArrayToBitmap(referenceBitmapBlurred).Save("test2.png");
//Helpers.ByteArrayToBitmap(testBitmapBlurred).Save("test1.png");
//Helpers.ByteArrayToBitmap(referenceBitmapBlurred).Save("test2.png");



Expand All @@ -392,9 +405,9 @@ public struct Color
testImgData[x, y, G] = testBitmap[testBitmap.stride * y + x * 4 + 1];
testImgData[x, y, R] = testBitmap[testBitmap.stride * y + x * 4 + 2];

refImgData[x, y, B] = (byte)Math.Max(0, Math.Min(255, ((float)referenceBitmap[referenceBitmap.stride * y + x * 4] / (float)referenceBitmapBlurred[referenceBitmapBlurred.stride * y + x * 4] * (float)testBitmapBlurred[testBitmapBlurred.stride * y + x * 4])));
refImgData[x, y, G] = (byte)Math.Max(0, Math.Min(255, ((float)referenceBitmap[referenceBitmap.stride * y + x * 4 + 1] / (float)referenceBitmapBlurred[referenceBitmapBlurred.stride * y + x * 4 + 1] * (float)testBitmapBlurred[testBitmapBlurred.stride * y + x * 4 + 1])));
refImgData[x, y, R] = (byte)Math.Max(0, Math.Min(255, ((float)referenceBitmap[referenceBitmap.stride * y + x * 4 + 2] / (float)referenceBitmapBlurred[referenceBitmapBlurred.stride * y + x * 4 + 2] * (float)testBitmapBlurred[testBitmapBlurred.stride * y + x * 4 + 2])));
refImgData[x, y, B] = ((float)referenceBitmap[referenceBitmap.stride * y + x * 4] / (float)referenceBitmapBlurred[referenceBitmapBlurred.stride * y + x * 4] * (float)testBitmapBlurred[testBitmapBlurred.stride * y + x * 4]);
refImgData[x, y, G] = ((float)referenceBitmap[referenceBitmap.stride * y + x * 4 + 1] / (float)referenceBitmapBlurred[referenceBitmapBlurred.stride * y + x * 4 + 1] * (float)testBitmapBlurred[testBitmapBlurred.stride * y + x * 4 + 1]);
refImgData[x, y, R] = ((float)referenceBitmap[referenceBitmap.stride * y + x * 4 + 2] / (float)referenceBitmapBlurred[referenceBitmapBlurred.stride * y + x * 4 + 2] * (float)testBitmapBlurred[testBitmapBlurred.stride * y + x * 4 + 2]);

/*debugBitmap.SetPixel(x, y, Color.FromArgb(testBitmap[testBitmap.stride * y + x * 3],
refImgData[x, y, G] = testBitmap[testBitmap.stride * y + x * 3 + 1],
Expand Down Expand Up @@ -1064,6 +1077,12 @@ private void LowPassMatch_radio_Checked(object sender, win.RoutedEventArgs e)
readGUISettings();
}


private void LowpassEqualizeBlurRadius_Text_TextChanged(object sender, win.Controls.TextChangedEventArgs e)
{
readGUISettings();
}

/*private void updateIter()
{
try
Expand Down

0 comments on commit 3ba70c8

Please sign in to comment.