I found a similar question emgu Calculate histogram with matrices ... but i'm missing some steps !
Emgu 3 / c# / Sql Server 2014
I'm trying to compare one Image with several Images stored in a varbinary(max) in SQL Server.
My first step of many, is to compare Histograms because some images (objects) may be the similar but with different colors, so in my comparison algorithm I also want to consider the color of the objects to compare.
I've manged to put some code together based on other posts here, and I'm able to successfully doing it, if I calculate the histograms based on the Images:
histBlueSource.Calculate(new Image<Gray, byte>[] { imgBlueSource }, true, null);
histBlueTarget.Calculate(new Image<Gray, byte>[] { imgBlueTarget }, true, null);
double cBlue = CvInvoke.CompareHist(histBlueSource, histBlueTarget, HistogramCompMethod.Correl);
Because of performance issues from loading the images from Database, I thought of extracting the BinValues from the histograms and just save them in the SQL SERVER database to later upload them back in a DenseHistogram.
I successfully extract the binvalues with:
//** problem may be here - dont know if i should SAVE/LOAD bin value to a 1d FLOAT[256]
float[] BlueHist = new float[256];
BlueHist = histBlue.GetBinValues();
I serialize, save to sql server. I can the read from sql server, deserialize and get back to a float[256] with my bin values, exactly as the extracted ones.
To load the data back to a Densehistogram I'm doing this:
DenseHistogram histBlue = new DenseHistogram(256, new RangeF(0.0f, 255.0f));
BlueHist = (float[])bformatterBlue.Deserialize(memStreamBlue);
//**Other problem may be here
Matrix<float> mtx = new Matrix<float>(BlueHist);
I find weird that Matrix data is {float[256,1]}. The values from the binvalues are then loaded from [0,0] to [255,0].
When I do the final step
histBlue.Calculate(new Matrix<float>[] { mtx }, false, null);
The problem is the histogram binvalues are not correctly loaded, only the [0] has a value of 135 and the others [255] are 0.
Can someone help me please with this or other suggestion to make the same?