public double Diff(GreyImage other) { byte[] src = (byte[])this.Data; byte[] dst = (byte[])other.Data; int diff = 0; int count = 0; for (int i = 0; i < Length; i++) { if (src[i] > 0 || dst[i] > 0) { count++; } if (src[i] != dst[i]) { diff++; } } if (count == 0) { return(0); } return(diff * 1.0 / count); }
public GreyImage(GreyImage refImage, int l, int t, int w, int h) { if (refImage == null) throw new System.ArgumentException("Input is invalid!"); int width = refImage.Width; int height = refImage.Height; if (l < 0) l = 0; if (l >= width) l = width - 1; if (t < 0) t = 0; if (t >= height) t = height - 1; if (l + w > width) w = width - l; if (t + h > height) h = height - t; if (w < 1) w = 1; if (h < 1) h = 1; // update image's info _width = w; _height = h; _length = _width * _height; // update image's data _data = Utilities.Crop((byte[])refImage.Data, 1, width, height, l, t, w, h); }
public Histogram(GreyImage image) { if (image == null) throw new System.ArgumentNullException("Input is invalid."); // calculate histogram's info this.Calc(image); }
public Histogram(GreyImage image) { if (image == null) { throw new System.ArgumentNullException("Input is invalid."); } // calculate histogram's info this.Calc(image); }
public GreyImage(GreyImage refImage, int l, int t, int w, int h) { if (refImage == null) { throw new System.ArgumentException("Input is invalid!"); } int width = refImage.Width; int height = refImage.Height; if (l < 0) { l = 0; } if (l >= width) { l = width - 1; } if (t < 0) { t = 0; } if (t >= height) { t = height - 1; } if (l + w > width) { w = width - l; } if (t + h > height) { h = height - t; } if (w < 1) { w = 1; } if (h < 1) { h = 1; } // update image's info _width = w; _height = h; _length = _width * _height; // update image's data _data = Utilities.Crop((byte[])refImage.Data, 1, width, height, l, t, w, h); }
public GreyImage( GreyImage refImage, int marginX, int marginY, bool trueIsExpanding_falseIsCropping, bool interpolationForExpandingOnly) { if (refImage == null) { throw new System.ArgumentException("Input is invalid!"); } int new_width = 0; int new_height = 0; byte[] new_data = null; if (trueIsExpanding_falseIsCropping) /* expand */ { if (interpolationForExpandingOnly) { new_data = Utilities.ExpandAndInterpolate( (byte[])refImage.Data, refImage.Width, refImage.Height, marginX, marginY, ref new_width, ref new_height); } else { new_data = Utilities.Expand( (byte[])refImage.Data, refImage.Width, refImage.Height, marginX, marginY, ref new_width, ref new_height); } } else /* crop */ { new_data = Utilities.Crop( (byte[])refImage.Data, 1, refImage.Width, refImage.Height, marginX, marginY, ref new_width, ref new_height); } // update image's info _width = new_width; _height = new_height; _length = _width * _height; // update image's data _data = new_data; }
public GreyImage(GreyImage refImage, bool cloneData) { if (refImage == null) throw new System.ArgumentException("Input is invalid!"); if (cloneData) { InitializeAndAllocateMemory(refImage.Width, refImage.Height); Array.Copy((byte[])refImage.Data, (byte[])_data, this.LengthByBytes); } else { InitializeWithoutAllocateMemory(refImage.Width, refImage.Height); _data = refImage.Data; } }
public GreyImage(GreyImage refImage, bool cloneData) { if (refImage == null) { throw new System.ArgumentException("Input is invalid!"); } if (cloneData) { InitializeAndAllocateMemory(refImage.Width, refImage.Height); Array.Copy((byte[])refImage.Data, (byte[])_data, this.LengthByBytes); } else { InitializeWithoutAllocateMemory(refImage.Width, refImage.Height); _data = refImage.Data; } }
public void Calc(GreyImage image) { if (image == null) throw new System.ArgumentNullException("Input is invalid."); // general initialization this.Initialize(); // get image's info int width = image.Width; int height = image.Height; int length = image.Length; TotalPixels = width * height; fixed (byte* data = (byte[])image.Data) { for (int i = 0; i < length; i++) { Bins[data[i]]++; TotalIntensity += data[i]; } } MeanIntensity = (float)(TotalIntensity * 1.0 / length); MedianIntensity = -1; int posMedian = length / 2; float count = 0; MinCount = float.MaxValue; MaxCount = float.MinValue; double totalSquareIntensity = 0; for (int i = 0; i < NumBins; i++) { if (Bins[i] == 0) continue; if (MinCount > Bins[i]) { MinCount = Bins[i]; MinBin = i; } if (MaxCount < Bins[i]) { MaxCount = Bins[i]; MaxBin = i; } if (MinIntensity >= i) MinIntensity = i; if (MaxIntensity <= i) MaxIntensity = i; totalSquareIntensity += Bins[i] * (i * i); if (MedianIntensity < 0) { count += Bins[i]; if (count > posMedian) MedianIntensity = i; } } double squareStdv = length * MeanIntensity * MeanIntensity - 2.0 * MeanIntensity * TotalIntensity + totalSquareIntensity; IntensityStdv = (float)Math.Sqrt(squareStdv); // search median of bin count // In case of the bins's size is large, // search engine should be implement based on The Z algorithm float[] tmp = new float[NumBins]; int[] indices = new int[NumBins]; Array.Copy(Bins, tmp, NumBins); for (int i = 0; i < NumBins; i++) indices[i] = i; Array.Sort(tmp, indices); MedianBin = indices[(NumBins - 1) / 2]; }
public GreyImage( GreyImage refImage, int marginX, int marginY, bool trueIsExpanding_falseIsCropping, bool interpolationForExpandingOnly) { if (refImage == null) throw new System.ArgumentException("Input is invalid!"); int new_width = 0; int new_height = 0; byte[] new_data = null; if (trueIsExpanding_falseIsCropping) /* expand */ { if (interpolationForExpandingOnly) { new_data = Utilities.ExpandAndInterpolate( (byte[])refImage.Data, refImage.Width, refImage.Height, marginX, marginY, ref new_width, ref new_height); } else { new_data = Utilities.Expand( (byte[])refImage.Data, refImage.Width, refImage.Height, marginX, marginY, ref new_width, ref new_height); } } else /* crop */ { new_data = Utilities.Crop( (byte[])refImage.Data, 1, refImage.Width, refImage.Height, marginX, marginY, ref new_width, ref new_height); } // update image's info _width = new_width; _height = new_height; _length = _width * _height; // update image's data _data = new_data; }
public double Diff(GreyImage other) { byte[] src = (byte[])this.Data; byte[] dst = (byte[])other.Data; int diff = 0; int count = 0; for (int i = 0; i < Length; i++) { if (src[i] > 0 || dst[i] > 0) count++; if (src[i] != dst[i]) diff++; } if (count == 0) return 0; return (diff * 1.0 / count); }
public void Calc(GreyImage image) { if (image == null) { throw new System.ArgumentNullException("Input is invalid."); } // general initialization this.Initialize(); // get image's info int width = image.Width; int height = image.Height; int length = image.Length; TotalPixels = width * height; fixed(byte *data = (byte[])image.Data) { for (int i = 0; i < length; i++) { Bins[data[i]]++; TotalIntensity += data[i]; } } MeanIntensity = (float)(TotalIntensity * 1.0 / length); MedianIntensity = -1; int posMedian = length / 2; float count = 0; MinCount = float.MaxValue; MaxCount = float.MinValue; double totalSquareIntensity = 0; for (int i = 0; i < NumBins; i++) { if (Bins[i] == 0) { continue; } if (MinCount > Bins[i]) { MinCount = Bins[i]; MinBin = i; } if (MaxCount < Bins[i]) { MaxCount = Bins[i]; MaxBin = i; } if (MinIntensity >= i) { MinIntensity = i; } if (MaxIntensity <= i) { MaxIntensity = i; } totalSquareIntensity += Bins[i] * (i * i); if (MedianIntensity < 0) { count += Bins[i]; if (count > posMedian) { MedianIntensity = i; } } } double squareStdv = length * MeanIntensity * MeanIntensity - 2.0 * MeanIntensity * TotalIntensity + totalSquareIntensity; IntensityStdv = (float)Math.Sqrt(squareStdv); // search median of bin count // In case of the bins's size is large, // search engine should be implement based on The Z algorithm float[] tmp = new float[NumBins]; int[] indices = new int[NumBins]; Array.Copy(Bins, tmp, NumBins); for (int i = 0; i < NumBins; i++) { indices[i] = i; } Array.Sort(tmp, indices); MedianBin = indices[(NumBins - 1) / 2]; }