Example #1
0
        private ResultImage SharpenTask(ImageJpeg file, Filter filter)
        {
            double[][] mask = new double[3][];
            mask[0] = new double[3] {
                -1.0, -1.0, -1.0
            };
            mask[1] = new double[3] {
                -1.0, 9.0, -1.0
            };
            mask[2] = new double[3] {
                -1.0, -1.0, -1.0
            };

            double factor = 1.0;
            double bias   = 0.0;

            byte[] imageResult = filter.FilterApply(file.ImageJpg, mask, factor, bias);

            new FileSaveTask(GeneratePhotoFileName(), imageResult).RunSynchronous();

            stopWatch.Stop();
            ResultImage result = new ResultImage(appConfig, EndpointController.rpcProfile, stopWatch.ElapsedMilliseconds);

            result.Image = imageResult;
            Debug.WriteLine("[BenchImage_DEBUG]: Adiciona no banco de dados local");
            dao.Add(result);

            return(result);
        }
Example #2
0
        private void Decompress()
        {
            Bitmap comprBitmap;

            if (VQCompression)
            {
                comprBitmap = VqDecompress();
            }
            else
            {
                _decompressStopWath = new Stopwatch();
                _decompressStopWath.Start();
                var comprImg    = (DwtImage)_compressed;
                var deflate     = new DeflateStream(new MemoryStream(_compressedData), CompressionMode.Decompress);
                var comprStream = new MemoryStream();
                deflate.CopyTo(comprStream);
                _compressedData = comprStream.ToArray();
                _compressedData = HuffmanEncoder.Decode(_compressedData);
                comprImg.FromByteArray(_compressedData);
                var img = RLE.DecompressImage(comprImg.Image, comprImg.Width, comprImg.Height);
                comprBitmap = ApplyHaarTransform(false, false, CodeBookSizePow, img);
                _decompressStopWath.Stop();
            }
            var stream = new MemoryStream();

            comprBitmap.Save(stream, ImageFormat.Png);
            ResultImage.BeginInit();
            ResultImage.StreamSource = stream;
            ResultImage.EndInit();
            OnPropertyChanged("ResultImage");
        }
Example #3
0
        public ResultImage ExecuteTask(ImageJpeg imageFile, Filter filter, AppConfiguration appConfig, string photoName, Stopwatch stopWatch)
        {
            this.filter    = filter;
            this.appConfig = appConfig;
            this.photoName = photoName;
            this.stopWatch = stopWatch;

            Debug.WriteLine("[BenchImage_DEBUG]: Iniciando aplicação de filtro");
            ResultImage result = null;

            switch (appConfig.Filter)
            {
            case "Original":
                result = OriginalTask(imageFile); break;

            case "Cartoonizer":
                result = CartoonizerTask(imageFile, filter); break;

            case "Benchmark":
                result = BenchmarkTask(filter); break;

            case "Sharpen":
                result = SharpenTask(imageFile, filter); break;

            default:
                result = FilterMapTask(imageFile, filter); break;
            }

            PhotoUtilities.ImageJpg  = null;
            PhotoUtilities.FilterJpg = null;
            GC.Collect();

            Debug.WriteLine("[BenchImage_DEBUG]: Finalizou aplicação de filtro");
            return(result);
        }
    protected void ResultAdd_Click(object sender, EventArgs e)
    {
        String className    = ResultClass.Text.Trim();
        String examName     = ResultExam.Text.Trim();
        Random randNum      = new Random();
        int    rann         = randNum.Next(10000);
        String randomNumber = rann.ToString();

        ResultImage.SaveAs(Server.MapPath("/dbimg/") + randomNumber + Path.GetFileName(ResultImage.FileName));
        String imgName = "/dbimg/" + randomNumber + Path.GetFileName(ResultImage.FileName);


        if (state == ConnectionState.Open)
        {
            conn.Close();
        }
        else
        {
            conn.Open();
            query = new SqlCommand("insert into Result (Class, Exam, Image) values('" + className + "','" + examName + "','" + imgName + "')", conn);
            query.ExecuteNonQuery();
            conn.Close();

            ResultClass.Text = "";
            ResultExam.Text  = "";
            ResultImage.Attributes.Clear();
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Added Result')", true);
        }
    }
Example #5
0
        private ResultImage CartoonizerTask(byte[] image, Filter filter)
        {
            if (appConfig.Filter.Equals("Benchmark"))
            {
                Stopwatch local       = Stopwatch.StartNew();
                byte[]    imageResult = filter.CartoonizerImage(image);

                new FileSaveTask(GeneratePhotoFileName(), imageResult).RunSynchronous();

                local.Stop();
                ResultImage result = new ResultImage(appConfig, EndpointController.rpcProfile, local.ElapsedMilliseconds);
                result.Image = imageResult;
                Debug.WriteLine("[BenchImage_DEBUG]: Adiciona no banco de dados local");
                dao.Add(result);

                return(result);
            }
            else
            {
                byte[] imageResult = filter.CartoonizerImage(image);

                new FileSaveTask(GeneratePhotoFileName(), imageResult).RunSynchronous();

                stopWatch.Stop();
                ResultImage result = new ResultImage(appConfig, EndpointController.rpcProfile, stopWatch.ElapsedMilliseconds);
                result.Image = imageResult;
                Debug.WriteLine("[BenchImage_DEBUG]: Adiciona no banco de dados local");
                dao.Add(result);

                return(result);
            }
        }
Example #6
0
 public void Save()
 {
     //ConvertTo8bpp(ResultImage, FileInfo.FullName);
     if (IsOptimzed)
     {
         ResultImage.Save(FileInfo.FullName, ImageFormat.Png);
     }
 }
 public void DrawRectanglesOnImage()
 {
     ResultImage = BaseImage.Copy();
     foreach (var rectangle in this.rectangles)
     {
         ResultImage.Draw(rectangle, new Bgr(Color.Blue), 1);
     }
 }
Example #8
0
        private ResultImage OriginalTask(ImageJpeg image)
        {
            stopWatch.Stop();
            ResultImage result = new ResultImage(appConfig, EndpointController.rpcProfile, stopWatch.ElapsedMilliseconds);

            result.Image = image.ImageJpg;
            return(result);
        }
 public void MarkLocationsOnImage()
 {
     ResultImage = BaseImage.Copy();
     foreach (var pt in Points)
     {
         ResultImage.Draw(new Cross2DF(pt, 10, 10), new Bgr(Color.Red), 2);
     }
 }
Example #10
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (ResultImage != null)
     {
         DialogResult result = saveFileDialog1.ShowDialog(); // Show the dialog. (File explorer)
         if (result == DialogResult.OK)                      // Test result.
         {
             ResultImage.Save(saveFileDialog1.FileName);
         }
     }
     else
     {
         MessageBox.Show("Please first convert image.", "Warning");
     }
 }
Example #11
0
        private ResultImage FilterMapTask(ImageJpeg file, Filter filter)
        {
            byte[] imageResult = filter.MapTone(file.ImageJpg, file.FilterJpg);

            new FileSaveTask(GeneratePhotoFileName(), imageResult).RunSynchronous();

            stopWatch.Stop();
            ResultImage result = new ResultImage(appConfig, EndpointController.rpcProfile, stopWatch.ElapsedMilliseconds);

            result.Image = imageResult;
            Debug.WriteLine("[BenchImage_DEBUG]: Adiciona no banco de dados local");
            dao.Add(result);

            return(result);
        }
Example #12
0
        private ResultImage BenchmarkTask(Filter filter)
        {
            ResultImage result = null;

            int count = 1;

            string[] sizes = { "8MP", "4MP", "2MP", "1MP", "0.3MP" };
            foreach (string size in sizes)
            {
                appConfig.Size = size;
                new ImageLoadBenchmark(size, appConfig.Image).RunSynchronous();
                for (int i = 0; i < 3; i++)
                {
                    Debug.WriteLine("Status: Benchmark [" + (count) + "/15]");
                    count++;

                    result = CartoonizerTask(PhotoUtilities.ImageJpg, filter);

                    if (count != 16)
                    {
                        result = null;
                        GC.Collect();
                        Thread.Sleep(750);
                    }
                }
                PhotoUtilities.ImageJpg = null;
                GC.Collect();
            }

            stopWatch.Stop();
            appConfig.Size = "Todos";
            ResultImage aggregateResult = new ResultImage(appConfig, EndpointController.rpcProfile, stopWatch.ElapsedMilliseconds);

            aggregateResult.Image = result.Image;

            dao.Add(aggregateResult);

            return(aggregateResult);
        }
Example #13
0
        private void GetResultImage(Interfaces.IContainer container, double countOfPixel)
        {
            if (container is Row)
            {
                GetAverageValue();

                foreach (var item in ListOfImages)
                {
                    ConvertImages.Add(GetImageWithAverageVolume(item, maxHeight: AverageHeight));
                }

                var proprotional = AllWidth / countOfPixel;

                foreach (var item in ConvertImages)
                {
                    ResultImage.Add(ResizeImageAfterAverageTransformation(item, proprotional));
                }

                foreach (var item in ResultImage)
                {
                    Window.StackP.Children.Add(item);
                }
            }
        }
Example #14
0
        private void LoadCompleteImage(ImageJpeg file)
        {
            ResultImage result = null;

            switch (AppConfig.Local)
            {
            case "Local":
                result = task.ExecuteTask(file, FilterLocal, AppConfig, photoName, stopWatch);
                break;

            case "Cloudlet":
                result = task.ExecuteTask(file, CloudletFilter, AppConfig, photoName, stopWatch);
                break;

            case "Internet":
                result = task.ExecuteTask(file, InternetFilter, AppConfig, photoName, stopWatch);
                break;
            }

            SetImageView(result.Image);

            ConfigureStatusView(result.TotalTime);

            ButtonExecute.Content   = "Inicia";
            ButtonExecute.IsEnabled = true;

            Dispatcher.BeginInvoke(() =>
            {
                this.TextStatus.Text = "Status: Terminou Processamento!";
            });

            //clean
            fileLoader.RunCompleted -= new RunCompletedEventHandler <ImageJpeg>(LoadCompleteImage);
            result = null;
            GC.Collect();
        }
Example #15
0
        public void Optimze()
        {
            if (!IsOptimzed)
            {
                return;
            }

            if (PublishTarget.Current.IsCacheEnabled && FileCacheCenter.IsInCache(FileInfo, Md5, FileCacheOperation.ImageOptimzed))
            {
                var fileInfo  = FileCacheCenter.GetCacheFileInfo(FileInfo, Md5, FileCacheOperation.ImageOptimzed);
                var cacheItem = FileCacheCenter.GetCacheFileItem(FileInfo, Md5, FileCacheOperation.ImageOptimzed);

                if (ResultImage != null)
                {
                    ResultImage.Dispose();
                    GC.Collect();
                    ResultImage = null;
                }


                //ResultImage = (Bitmap)Bitmap.FromFile(fileInfo.FullName);
                ResultSize = GetImageSize(fileInfo);

                if (cacheItem.TextureRect != null)
                {
                    Rectangle rect = new Rectangle();
                    rect.X      = (int)cacheItem.TextureRect.Origin.X;
                    rect.Y      = (int)cacheItem.TextureRect.Origin.Y;
                    rect.Width  = (int)cacheItem.TextureRect.Size.Width;
                    rect.Height = (int)cacheItem.TextureRect.Size.Height;
                    TextureRect = rect;
                }

                if (cacheItem.Offset != null)
                {
                    Point pos = new Point();
                    pos.X = (int)cacheItem.Offset.X;
                    pos.Y = (int)cacheItem.Offset.Y;

                    Offset = pos;
                }

                Logger.LogInfoLine("FileCache Hit:Optimze {0} ", FileInfo.FullName);
                UpdateFileInfo(fileInfo);
            }
            else
            {
                var originalImage = (Bitmap)Bitmap.FromFile(FileInfo.FullName);

                var leftBottom = new Point(int.MaxValue, int.MaxValue);
                var rightTop   = Point.Empty;

                bool isBreak = false;
                for (int i = 0; i < originalImage.Width; i++)
                {
                    for (int j = 0; j < originalImage.Height; j++)
                    {
                        var color = originalImage.GetPixel(i, j);
                        if (color.A != 0)
                        {
                            leftBottom.X = i;
                            isBreak      = true;
                            break;
                        }
                    }
                    if (isBreak)
                    {
                        break;
                    }
                }

                isBreak = false;
                for (int i = originalImage.Width - 1; i >= 0; i--)
                {
                    for (int j = 0; j < originalImage.Height; j++)
                    {
                        var color = originalImage.GetPixel(i, j);
                        if (color.A != 0)
                        {
                            rightTop.X = i;
                            isBreak    = true;
                            break;
                        }
                    }
                    if (isBreak)
                    {
                        break;
                    }
                }

                isBreak = false;
                for (int i = 0; i < originalImage.Height; i++)
                {
                    for (int j = 0; j < originalImage.Width; j++)
                    {
                        var color = originalImage.GetPixel(j, i);
                        if (color.A != 0)
                        {
                            leftBottom.Y = i;
                            isBreak      = true;
                            break;
                        }
                    }
                    if (isBreak)
                    {
                        break;
                    }
                }

                isBreak = false;
                for (int i = originalImage.Height - 1; i >= 0; i--)
                {
                    for (int j = 0; j < originalImage.Width; j++)
                    {
                        var color = originalImage.GetPixel(j, i);
                        if (color.A != 0)
                        {
                            rightTop.Y = i;
                            isBreak    = true;
                            break;
                        }
                    }
                    if (isBreak)
                    {
                        break;
                    }
                }

                var clipRect = new Rectangle(leftBottom,
                                             new Size(rightTop.X - leftBottom.X + 1, rightTop.Y - leftBottom.Y + 1));
                if (leftBottom.X == int.MaxValue || leftBottom.Y == int.MaxValue)
                {
                    ResultImage = originalImage;

                    Logger.LogError("Empty image:{0}\r\n", FileInfo);
                }
                else
                {
                    if (clipRect.Size != originalImage.Size)
                    {
                        Offset      = new Point(leftBottom.X, originalImage.Size.Height - clipRect.Bottom);
                        ResultImage = ClipImage(originalImage, clipRect);
                        originalImage.Dispose();
                        ResultSize = ResultImage.Size;
                    }
                    else
                    {
                        ResultImage = originalImage;
                    }
                }

                if (PublishTarget.Current.IsCacheEnabled)
                {
                    var newFileInfo = FileCacheCenter.GetCacheNewFileInfo(FileInfo.FullName, FileCacheOperation.ImageOptimzed);
                    if (newFileInfo.Exists)
                    {
                        newFileInfo.Delete();
                    }
                    ResultImage.Save(newFileInfo.FullName, ImageFormat.Png);
                    FileCacheCenter.AddToCacheWithoutCopy(Md5, FileInfo, TextureRect, Offset, FileCacheOperation.ImageOptimzed);

                    UpdateFileInfo(newFileInfo);
                }
                else
                {
                    UpdateFileInfo(FileInfo);
                }

                ResultImage.Dispose();
                GC.Collect();
                ResultImage = null;
            }

            //Logger.LogInfoLine("Optimze image:{0}", ToString());
        }
Example #16
0
        private void SquezeButton_Click(object sender, EventArgs e)
        {
            if (selectedState == null)
            {
                DialogResult rezult = MessageBox.Show("Choose image fourth.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            else if (SourceImage.Image == null)
            {
                DialogResult rezult = MessageBox.Show("Choose image.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            else
            {
                SaveButton.Location = new Point(OpenButton.Location.X, OpenButton.Location.Y);
                SaveButton.Show();
                FileName.Text = "File path ...";
                OpenButton.Hide();

                for (int i = 0; i < 256; i++)
                {
                    ArrR[i]  = new double[256];
                    ArrG[i]  = new double[256];
                    ArrB[i]  = new double[256];
                    ArrR1[i] = new double[256];
                    ArrG1[i] = new double[256];
                    ArrB1[i] = new double[256];
                }

                code.ImageToArray(image, ref ArrR, ref ArrG, ref ArrB, sFileName);
                code.Fragmentation(ArrR, ArrG, ArrB, coordX, coordY);
                code.Comprassion(ref timeMain, ref timeBg);
                code.Merge(ref ArrR1, ref ArrG1, ref ArrB1);
                code.Calculation(ref SKO, ref PSNR, ArrR, ArrG, ArrB, ArrR1, ArrG1, ArrB1);
                code.ArrayToImage(ref image, ArrR1, ArrG1, ArrB1);
                ResultImage.Image = image;
                ResultImage.Invalidate();
                sFileName = "C:\\Users\\Public\\Documents\\AdaptiveComprassion\\tmp";
                System.IO.Directory.CreateDirectory("C:\\Users\\Public\\Documents\\AdaptiveComprassion");
                if (System.IO.File.Exists(sFileName))
                {
                    do
                    {
                        sFileName += DateTime.Now.Minute;
                    } while (System.IO.File.Exists(sFileName));
                }
                image.Save(sFileName, System.Drawing.Imaging.ImageFormat.Png);
                FileInfo imageInfo = new FileInfo(sFileName);
                resultSizeInKBytes = Convert.ToInt32(imageInfo.Length / 1024);
                File.Delete("C:\\Users\\Public\\Documents\\AdaptiveComprassion\\tmp");
                sFileName = null;

                conn.Open();
                string insert = "INSERT INTO Characteristics (Data, InputS, OutputS, RatioMain, RatioBg, TimeMain, TimeBg, NN1, NN2, SKO, PSNR) VALUES ( ";
                insert += "'" + Dat.ToString() + "', " + sourceSizeInKBytes + ", " + resultSizeInKBytes + ", 2 , 4, " + timeMain + ", " + timeBg + ", '{64;32;64}', '{64;16;64}', " + "'" + SKO.ToString() + "', " + "'" + PSNR.ToString() + "')";
                SQLiteCommand ins = new SQLiteCommand(insert, conn);
                ins.ExecuteNonQuery();
                conn.Close();

                SquezeButton.Enabled = false;
            }
        }
Example #17
0
 private void SaveResutlImageToStorage(ResultImage resultImage)
 {
     _imageStorage.Save(resultImage.ImageId, resultImage, DateTime.Now.AddHours(1));
 }
Example #18
0
 public void Add(ResultImage result)
 {
     table.InsertOnSubmit(result);
     SubmitChanges();
 }