예제 #1
0
        public void GenerateBitmap(int imageSize)
        {
            this.Bitmap       = DrawStrokes(this.Strokes, imageSize, imageSize, this.InkCanvasSize.Width, this.InkCanvasSize.Height);
            this.BitmapColors = UtilityWPF.ConvertToColorArray(this.Bitmap, true, Colors.Transparent);

            this.NNInput = this.BitmapColors.GetColors(0, 0, imageSize, imageSize).
                           Select(o => (o.A / 255d) * (255d - Math1D.Avg(o.R, o.G, o.B)) / 255d). // 0 should be 1d, 255 should be 0d
                           ToArray();
        }
예제 #2
0
        /// <summary>
        /// Converts the original image into a grayscale
        /// </summary>
        private Convolution2D GetOriginalImageGrays()
        {
            if (originalImage.Source == null)
            {
                return(null);
            }

            int?limit = null;
            int limitInt;

            if (chkLimitImageSize.IsChecked.Value && int.TryParse(txtSizeLimit.Text, out limitInt))
            {
                limit = limitInt;
            }

            bool shouldBuild = false;

            if (_origImageGrays == null)
            {
                shouldBuild = true;
            }
            else if (limit != null && (_origImageGrays.Width > limit.Value || _origImageGrays.Height > limit.Value))
            {
                // The current one is the wrong size
                shouldBuild = true;
            }

            if (shouldBuild)
            {
                BitmapSource bitmap = (BitmapSource)originalImage.Source;

                BitmapCustomCachedBytes colors = null;

                if (limit != null)
                {
                    bitmap = UtilityWPF.ResizeImage(bitmap, limit.Value);       // this will only resize if it's too big
                }

                colors = (BitmapCustomCachedBytes)UtilityWPF.ConvertToColorArray(bitmap, false, Colors.Transparent);

                _origImageGrays = colors.ToConvolution();
            }

            return(_origImageGrays);
        }