public void PaintFire(ByteArrayBitmap bmp) { byte[] firecolor = new byte[] { 0, 0, 255 }; byte[] watercolor = new byte[] { 255, 0, 0 }; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { if (_firemap[x, y].IsOnFire) { bmp.SetColor(x, y, firecolor); } else if (_firemap[x, y].Burned) { byte[] pixel = bmp.GetColor(x, y); pixel[0] = (byte)(pixel[0] / 5); pixel[1] = (byte)(pixel[1] / 5); pixel[2] = (byte)(pixel[2] / 5); bmp.SetColor(x, y, pixel); } else if (_firemap[x, y].Water > 125) { bmp.SetColor(x, y, watercolor); } } } }
private void _ThresholdButton_Click(object sender, RoutedEventArgs e) { int[] bgr = ParseBGR(_BGRTextBox.Text); ByteArrayBitmap rbmp = _bmp.Clone(); byte[] truebyte = new byte[] { 255, 255, 255 }; byte[] falsebyte = new byte[] { 0, 0, 0 }; numbergrid = new int[_bmp.Width, _bmp.Height]; for (int x = 0; x < rbmp.Width; x++) { for (int y = 0; y < rbmp.Height; y++) { byte[] c = rbmp.GetColor(x, y); bool t = true; if (c[0] != bgr[0] || c[1] != bgr[1] || c[2] != bgr[2]) { t = false; } rbmp.SetColor(x, y, t?truebyte:falsebyte); numbergrid[x, y] = t ? 1 : 0; } } _image.Source = rbmp.ToBitmapSource(); }
private void Start() { _continue = true; Task.Factory.StartNew(() => { while (_continue) { Dispatcher.BeginInvoke(new Action(() => { try { _time.Text = time.ToString(); if (bkg == null) { _image.Source = firemap.ToByteArrayBitmap().ToBitmapSource(); } else { ByteArrayBitmap b = bkg.Clone(); firemap.PaintFire(b); _image.Source = b.ToBitmapSource(); } } catch (Exception ee) { } })); firemap.Update(); time = time.AddHours(6); Thread.Sleep(150); } }); }
protected void Initialize(ByteArrayBitmap bitmap, byte[] encodedData, ContentType encodedDataContentType, DateTime dbtime, bool decode) { if ((bitmap == null) && (encodedData == null)) { return; } this.DBTime = dbtime; _bitmap = bitmap; this.EncodedData = encodedData; this.EncodedDataContentType = encodedDataContentType; if (bitmap == null && decode) { this.TryToDecodeEncodedDataTo_bitmap(); } if (encodedData == null) { this.EncodeBitmap(new JpegBitmapEncoder { QualityLevel = JpegBitmapEncoderFactory.DefaultJpegQuality }); } TrySetWidthHeight(); }
protected void SetResultImage(ByteArrayBitmap im) { _ResultImage = im; if (NewResultImageSet != null) { NewResultImageSet(this, null); } }
public BitmapHistogram(ByteArrayBitmap bitmap) { _Channels[0] = new BitmapHistogramChannel(); _Channels[1] = new BitmapHistogramChannel(); _Channels[2] = new BitmapHistogramChannel(); //MapImage_RGB(bitmap); MapImage_HLS(bitmap); }
/// <summary> /// Will Drop data if there is suitable encoded data available /// </summary> /// <returns></returns> public bool TryDropBitmapDeinterlacedData() { if (this.EncodedData != null) { _bitmapDeinterlaced = null; } return(_bitmap == null); }
public void Dispose() { if (this.Data != null) { ByteArrayBitmap.DeAllocateBytes(this.Data); } this.Data = null; }
public BitmapHistogram(ByteArrayBitmap bitmap, int x, int y, int width, int height) { _Channels[0] = new BitmapHistogramChannel(); _Channels[1] = new BitmapHistogramChannel(); _Channels[2] = new BitmapHistogramChannel(); //MapImage_RGB(bitmap); MapImage_HLS(bitmap, x, y, width, height); }
public HLSImage(int width, int height, int channels) { _bytesPerPixel = channels; Width = width; Height = height; Stride = width * channels; Data = ByteArrayBitmap.MakeBytes(Stride * Height); //new byte[Stride * Height]; }
private void OpenButton_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog().Value) { _bmp = ByteArrayBitmap.FromFile(dialog.FileName); _image.Source = _bmp.ToBitmapSource(); } }
private void _MapHueButton_Click(object sender, RoutedEventArgs e) { bool R = _RChannel.IsChecked.Value; bool G = _GChannel.IsChecked.Value; bool B = _BChannel.IsChecked.Value; double max = 255; byte[] refc = new byte[] { (byte)(R ? 255 : 0), (byte)(G ? 255 : 0), (byte)(B ? 255 : 0) }; numbergrid = new int[_bmp.Width, _bmp.Height]; double hue = HLSImage.RGBToHLS(refc)[0]; ByteArrayBitmap rbmp = _bmp.Clone(); for (int x = 0; x < rbmp.Width; x++) { for (int y = 0; y < rbmp.Height; y++) { byte[] bgr = rbmp.GetColor(x, y); byte[] rgb = new byte[] { bgr[2], bgr[1], bgr[0] }; byte[] c = HLSImage.RGBToHLS(rgb); //.GetColor(x, y); byte dist = (byte)(Math.Abs(c[0] - hue)); byte val = (byte)(dist < 25?bgr[1]: 0); byte[] outc = new byte[] { 0, val, 0 }; //new byte[] //{ // (byte)(B? c[0]:0), // (byte)(G? c[1]:0), // (byte)(R? c[2]:0) //}; numbergrid[x, y] = val; if (max < numbergrid[x, y]) { max = numbergrid[x, y]; } rbmp.SetColor(x, y, outc); } } _image.Source = rbmp.ToBitmapSource(); //normalise for (int x = 0; x < rbmp.Width; x++) { for (int y = 0; y < rbmp.Height; y++) { numbergrid[x, y] = (int)(100 * ((double)numbergrid[x, y] / max)); } } }
public VideoFrame(ByteArrayBitmap bitmap, DateTime dbtime, bool clone) { if (bitmap == null) { throw new ArgumentNullException("bitmap"); } ByteArrayBitmap bmp = (clone ? bitmap.Clone() : bitmap); this.Initialize(bmp, null, null, dbtime, false); }
/// <summary> /// Will Drop data if there is suitable encoded data available /// </summary> /// <returns></returns> public bool TryDropBitmapData() { if (this.EncodedData != null) { if (_bitmap != null) { _bitmap.Dispose(); } _bitmap = null; } return(_bitmap == null); }
public CompressedByteArrayBitmap(ByteArrayBitmap sourceBmp) : base(sourceBmp.Width, sourceBmp.Height, sourceBmp.Format) { this.BytesPerPixel = sourceBmp.BytesPerPixel; this.Width = sourceBmp.Width; this.Height = sourceBmp.Height; this.Stride = sourceBmp.Stride; this.Format = sourceBmp.Format; //now that everything needed is set, compress this.Data = sourceBmp.Data; }
private void MapImage_RGB(ByteArrayBitmap bitmap) { int bindiv = 256 / 8; for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { for (int c = 0; c < 3; c++) { int p = bitmap.GetColorValue(i, j, c) / bindiv; Channels[c].Bins[p]++; } } } }
private void OpenButton_Click(object sender, RoutedEventArgs e) { //NationalPark //string burnedDataFile = @"D:\Dropbox\Personal\NASASpaceApps\data\BurnedArea.csv"; //string fireStartPointDataFile = @"D:\Dropbox\Personal\NASASpaceApps\data\FireStartPoints.csv"; //string VegitationDataFile = @"D:\Dropbox\Personal\NASASpaceApps\data\VegitationResources_2.csv"; //string WaterDataFile = @"D:\Dropbox\Personal\NASASpaceApps\data\WaterResources.csv"; //bkg = ByteArrayBitmap.FromFile(@"D:\Dropbox\Personal\NASASpaceApps\data\Bkg_Map.jpg"); //Brisbane //string burnedDataFile = @"D:\Dropbox\Personal\NASASpaceApps\data\BurnedArea.csv"; //string fireStartPointDataFile = @"D:\Dropbox\Personal\NASASpaceApps\data\FireStartPoints.csv"; string VegitationDataFile = @"D:\Dropbox\Personal\NASASpaceApps\Brisbane\BrisbaneSmallVeg.csv"; //string WaterDataFile = @"D:\Dropbox\Personal\NASASpaceApps\data\WaterResources.csv"; bkg = ByteArrayBitmap.FromFile(@"D:\Dropbox\Personal\NASASpaceApps\Brisbane\SmallBrisbane.jpg"); //int[,] waterdata = CSVReader.Read(WaterDataFile); int[,] VegData = CSVReader.Read(VegitationDataFile); //int[,] firestartData = CSVReader.Read(fireStartPointDataFile); //int[,] burnedData = CSVReader.Read(burnedDataFile); int width = VegData.GetUpperBound(0) + 1; int height = VegData.GetUpperBound(1) + 1; firemap = new FireMap(width, height); firemap.FireCells = new FireCell[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { firemap.FireCells[x, y] = new FireCell() { Fuel = VegData[x, y], //FireIntensity = firestartData[x, y]*255, //Water = waterdata[x,y] }; } } firemap.RandomFireStarts(); //firemap.WindXIntensity = 15; _image.Source = bkg.ToBitmapSource(); }
private void _MapChannelButton_Click(object sender, RoutedEventArgs e) { bool R = _RChannel.IsChecked.Value; bool G = _GChannel.IsChecked.Value; bool B = _BChannel.IsChecked.Value; ByteArrayBitmap rbmp = _bmp.Clone(); double max = 255; numbergrid = new int[_bmp.Width, _bmp.Height]; for (int x = 0; x < rbmp.Width; x++) { for (int y = 0; y < rbmp.Height; y++) { byte[] c = rbmp.GetColor(x, y); byte[] outc = new byte[] { (byte)(B? c[0]:0), (byte)(G? c[1]:0), (byte)(R? c[2]:0) }; numbergrid[x, y] = outc[0] + outc[1] + outc[2]; if (max < numbergrid[x, y]) { max = numbergrid[x, y]; } rbmp.SetColor(x, y, outc); //numbergrid[x, y] = t ? 1 : 0; } } _image.Source = rbmp.ToBitmapSource(); //normalise for (int x = 0; x < rbmp.Width; x++) { for (int y = 0; y < rbmp.Height; y++) { numbergrid[x, y] = (int)(100 * ((double)numbergrid[x, y] / max)); } } }
protected byte[] Decompress() { byte[] data = null; try { BitmapDecoder decoder; using (MemoryStream memoryStream = new MemoryStream(_CompressedData)) decoder = BitmapDecoder.Create(memoryStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); BitmapFrame bitmapFrame = decoder.Frames[0]; data = new ByteArrayBitmap(bitmapFrame).Data; //bitmapFrame.CopyPixels(data, this.Stride, 0); } catch (Exception ee) { DebugMessageLogger.LogError(ee); } return(data); }
public ByteArrayBitmap ToByteArrayBitmap() { if (_bmp == null || _bmp.Width != Width || _bmp.Height != Height) { _bmp = new ByteArrayBitmap(Width, Height, PixelFormats.Bgr24); } byte[] firecolor = new byte[] { 0, 0, 255 }; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { _bmp.SetColor(x, y, _firemap[x, y].GetColor()); } } return(_bmp); }
private void TryToDecodeEncodedDataTo_bitmap() { try { lock (_disposelock) { if (Disposed) { return; } using (MemoryStream memoryStream = new MemoryStream(this.EncodedData)) { System.Drawing.Bitmap bmp = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(memoryStream); _bitmap = ByteArrayBitmap.FromBitmapForce4bpp(bmp); } //this was the way it was done in 2.5 and below //BitmapDecoder decoder; //using (MemoryStream memoryStream = new MemoryStream(this.EncodedData)) // decoder = BitmapDecoder.Create(memoryStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); //BitmapFrame bitmapFrame = decoder.Frames[0]; //_bitmap = new ByteArrayBitmap(bitmapFrame); //string[] mimeTypes = decoder.CodecInfo.MimeTypes.Split(','); //if (mimeTypes.Length > 0) // this.EncodedDataContentType = new ContentType(mimeTypes[0]); // log access for drop on age calc this.EncodedDataContentType = new ContentType("image/jpeg"); _lastDecodedDataAccess = DateTime.Now; TrySetWidthHeight(); } } catch (Exception ee) { System.Diagnostics.Trace.WriteLine(string.Format("No Bitmap and No EncodedData: {0}.{1}", DBTime, DBTime.Millisecond)); DebugMessageLogger.LogError(ee); _bitmap = null; } }
public void AddNewFrameData(DateTime time, ByteArrayBitmap bitmap) { ///debug _countAdded++; byte[] jpegdata = null; JpegBitmapEncoder encoder = new JpegBitmapEncoder { QualityLevel = 96 }; encoder.Frames.Add(BitmapFrame.Create(bitmap.ToBitmapSource())); using (MemoryStream imageMemoryStream = new MemoryStream()) { encoder.Save(imageMemoryStream); jpegdata = imageMemoryStream.ToArray(); } _jpegDataIndex.Add(new KeyValuePair <DateTime, byte[]>(time, jpegdata)); }
public void MapImage_HLS(ByteArrayBitmap bitmap) { //if bitmap is 4 byte per pixel, then ignore transparent pixels; bool ignoreTransparent = bitmap.BytesPerPixel == 4; double countsamples = 0; int bindiv = 256 / 8; for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { byte[] pixel = bitmap.GetColor(i, j); if (ignoreTransparent && pixel[3] != 255) { //ignore } else { byte[] hls = HLSImage.RGBToHLS(pixel); countsamples++; for (int c = 0; c < 3; c++) { int p = hls[c] / bindiv; Channels[c].Bins[p]++; } } } } for (int c = 0; c < 3; c++) { for (int p = 0; p < Channels[c].NumberOfBins; p++) { Channels[c].Bins[p] /= countsamples; } } }
/// <summary> /// Returns a BAB containing the values where the two images match. /// Images must be same size etc... /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <returns></returns> public static ByteArrayBitmap VoteCombiner(ByteArrayBitmap A, ByteArrayBitmap B) { try { if (A.Width != B.Width) { throw new Exception("image error"); } if (A.Height != B.Height) { throw new Exception("image error"); } if (A.Data.Length != B.Data.Length) { throw new Exception("image error"); } byte[] data = new byte[A.Data.Length]; for (int i = 0; i < A.Data.Length; i++) { if (A.Data[i] == B.Data[i]) { data[i] = A.Data[i]; } else { data[i] = 0; } } return(new ByteArrayBitmap(data, A.Width, A.Height, A.Format)); } catch (Exception ker) { Kinesense.Interfaces.DebugMessageLogger.LogError(ker); return(null); } }
public void Rotate(System.Drawing.RotateFlipType rotate) { try { System.Drawing.Bitmap B = this.Bitmap.ToBitmap(); B.RotateFlip(rotate); using (MemoryStream memoryStream = new MemoryStream()) { B.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp); B.Dispose(); memoryStream.Seek(0, SeekOrigin.Begin); byte[] data = new byte[memoryStream.Length]; memoryStream.Read(data, 0, (int)memoryStream.Length); _bitmap = new ByteArrayBitmap(data); } } catch (Exception ee) { DebugMessageLogger.LogError(ee); } }
public void Dispose() { lock (_disposelock) { if (!this.Disposed) { _disposeCallLog = Environment.StackTrace; if (SuppressDispose) { return; } if (this._bitmap != null) { this._bitmap.Dispose(); this._bitmap = null; } if (this._bitmapDeinterlaced != null) { this._bitmapDeinterlaced.Dispose(); this._bitmapDeinterlaced = null; } if (this._bitmapSource != null) { this._bitmapSource = null; } //not needed. //if (EncodedData != null) // ByteArrayBitmap.DeAllocateBytes(EncodedData); this.FrameHash.Dispose(); //this.NextFrameTime = null; //this.PreviousFrameTime = null; this.Disposed = true; } } GC.SuppressFinalize(this); }
/// <summary> /// Will Drop data if there is suitable encoded data available /// </summary> /// <returns></returns> public bool TryDropDecodedData() { if (this.EncodedData != null) { if (_bitmap != null) { _bitmap.Dispose(); } _bitmap = null; if (_bitmapDeinterlaced != null) { _bitmapDeinterlaced.Dispose(); } _bitmapDeinterlaced = null; _bitmapSource = null; } return(_bitmap == null); }
/// <summary> /// Returns an image that is the result of a simple regional analysis on the source images /// Look at the code to see what it really does /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <param name="reqScore"></param> /// <param name="centreScore"></param> /// <returns></returns> public static ByteArrayBitmap VoteCombinerLocal(ByteArrayBitmap A, ByteArrayBitmap B, int reqScore, int centreScore) { try { if (A.Width != B.Width) { throw new Exception("image error"); } if (A.Height != B.Height) { throw new Exception("image error"); } if (A.Data.Length != B.Data.Length) { throw new Exception("image error"); } byte[] data = new byte[A.Data.Length]; unsafe { fixed(byte *AStart = &A.Data[0], BStart = &B.Data[0], DStart = &data[0]) { // a,b,c // d,e,f // g,h,i int span = A.Width * A.BytesPerPixel; byte *[] a = new byte *[9]; byte *[] b = new byte *[9]; a[0] = AStart; a[1] = AStart + 1 * A.BytesPerPixel; a[2] = AStart + 2 * A.BytesPerPixel; a[3] = AStart + span; a[4] = AStart + span + 1 * A.BytesPerPixel; a[5] = AStart + span + 2 * A.BytesPerPixel; a[6] = AStart + span + span; a[7] = AStart + span + span + 1 * A.BytesPerPixel; a[8] = AStart + span + span + 2 * A.BytesPerPixel; b[0] = BStart; b[1] = BStart + 1 * A.BytesPerPixel; b[2] = BStart + 2 * A.BytesPerPixel; b[3] = BStart + span; b[4] = BStart + span + 1 * A.BytesPerPixel; b[5] = BStart + span + 2 * A.BytesPerPixel; b[6] = BStart + span + span; b[7] = BStart + span + span + 1 * A.BytesPerPixel; b[8] = BStart + span + span + 2 * A.BytesPerPixel; byte *dest = DStart + span + A.BytesPerPixel; for (int z = 1; z < A.Height - 1; z++) { for (int y = 1; y < A.Width - 1; y++) { for (int x = 0; x < A.BytesPerPixel; x++) { int score1 = 0; int score2 = 0; for (int i = 0; i < 9; i++) { if (*a[i] > 200) { if (i != 4) { score1++; } else { score1 += centreScore; } } if (*b[i] > 200) { if (i != 4) { score2++; } else { score2 += centreScore; } } if (z != A.Height - 2 || y != A.Width - 2) { a[i]++; b[i]++; } } if (score1 >= reqScore && score2 >= reqScore) { *dest = 255; } else { *dest = 0; } dest++; } } if (z != A.Height - 2) { for (int i = 0; i < 9; i++) { a[i] += 2 * A.BytesPerPixel; b[i] += 2 * A.BytesPerPixel; } dest += 2 * A.BytesPerPixel; } } } } return(new ByteArrayBitmap(data, A.Width, A.Height, A.Format)); } catch (Exception ker) { Kinesense.Interfaces.DebugMessageLogger.LogError(ker); return(null); } }
public TimedByteArrayBitmap(ByteArrayBitmap bmp, DateTime time) : base(bmp) { Time = time; }
public VideoFrame(ByteArrayBitmap bitmap, DateTime dbtime) : this(bitmap, dbtime, false) { }