Şimdi Ara

Resimde Siyah ve Beyaz dışında bulunan tüm renkleri siyah yapmak.

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir - 2 Masaüstü
5 sn
8
Cevap
0
Favori
959
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • Merhaba çalıştığım kurumda yazmakta olduğum bir geliştirme programı için screenshot yaptığım bir resimde yer alan siyah ve beyaz dışında (kırmızı mühür, mavi mühür, imza için kullanılan mavi tükenmez kalem gibi ve benzeri tüm renkler) renkleri beyaz ton yapmasını sağmamam lazım. Bu sayede ekranda bulunan bir resimde OCR yaparak "Evrak Sayısı" üzerine gelen kırmızı postahane mühürlerini gizleyerek okutma yapmak istiyorum. Bir tavsiyeniz veya ipucu önerileriniz var mı ? Nasıl bir yol izleyerek başlayım sizce ?




  • Siyah ve beyaz tek renk degil, bir suru tonu var. O yuzden bir esik degeri belirlemen lazim.

  • quote:

    Orijinalden alıntı: seyfi84

    Bu mesaj silindi.

    anladım çok teşekkür ederim yine de araştıracağım umarım tam otonom bir sonuç buluruz.

  • controller_ kullanıcısına yanıt

    Yanıtınız için teşekkür ederim dikkate alarak ilerleyeceğim.

  • tam bir çözümü yok çünkü renk seçince diğer renkler kaybolabilir örnek uygulama yaptım ImageColor isminde bir wpf projesi açıp kodları uygularsın


    Kod

    Yığını:


    Kod

    Yığını:
    <Window x:Class="ImageColor.MainWindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:ImageColor"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     Title="Renk Beyaza Çevirici"     Width="800" Height="450"     WindowState="Maximized"     mc:Ignorable="d">     <Grid>         <Grid.ColumnDefinitions>             <ColumnDefinition />             <ColumnDefinition />         </Grid.ColumnDefinitions>         <Grid>             <Grid.RowDefinitions>                 <RowDefinition Height="Auto" />                 <RowDefinition Height="Auto" />                 <RowDefinition />                 <RowDefinition Height="Auto" />             </Grid.RowDefinitions>             <Button Content="RESİM AÇ" Grid.Row="0" Click="Button_Click" />             <Slider x:Name="Sld"                 Grid.Row="1"                 Maximum="255" Minimum="1" ValueChanged="Sld_ValueChanged" />             <Image x:Name="Img"                 Grid.Row="2"                 MouseLeftButtonDown="Img_MouseLeftButtonDown" MouseMove="Img_MouseMove" PreviewMouseMove="Grid_PreviewMouseMove" />             <Grid Grid.Row="3"                 Width="100" Height="100"                 ShowGridLines="True">                 <Grid.RowDefinitions>                     <RowDefinition />                     <RowDefinition />                 </Grid.RowDefinitions>                 <Grid.ColumnDefinitions>                     <ColumnDefinition />                     <ColumnDefinition />                 </Grid.ColumnDefinitions>                 <Canvas x:Name="cnv"                     Grid.RowSpan="2" Grid.ColumnSpan="2"                     IsHitTestVisible="False">                     <Rectangle x:Name="rct"                         Width="{Binding ElementName=cnv, Path=ActualWidth}"                         Height="{Binding ElementName=cnv, Path=ActualHeight}"                         Stroke="Black" StrokeThickness="1">                         <Rectangle.Fill>                             <VisualBrush Viewbox="0,0,25,25" ViewboxUnits="Absolute" Viewport="0,0,1,1" ViewportUnits="RelativeToBoundingBox" />                         </Rectangle.Fill>                     </Rectangle>                 </Canvas>             </Grid>         </Grid>         <Image x:Name="Img2" Grid.Column="1" />     </Grid> </Window>


    Kod

    Yığını:
    using Microsoft.Win32; using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using Color = System.Drawing.Color; using Rectangle = System.Drawing.Rectangle; namespace ImageColor {     public partial class MainWindow : Window     {         private static OpenFileDialog openFileDialog;         private byte[] pixels;         public MainWindow()         {             InitializeComponent();             ((VisualBrush)rct.Fill).Visual = Img;         }         private System.Windows.Media.Color GeçiciRenk { get; set; }         private System.Windows.Media.Color Renk { get; set; }         public static BitmapSource GetImageStream( System.Drawing.Image bitmap, System.Drawing.Imaging.ImageFormat format, double decodeheight = 0)         {             if (bitmap != null)             {                 MemoryStream memoryStream = new MemoryStream();                 bitmap.Save(memoryStream, format);                 memoryStream.Position = 0;                 BitmapImage image = new BitmapImage();                 image.BeginInit();                 if (decodeheight != 0)                 {                     image.DecodePixelHeight = bitmap.Height > (int)decodeheight ? (int)decodeheight : bitmap.Height;                 }                 image.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;                 image.CacheOption = BitmapCacheOption.None;                 image.StreamSource = memoryStream;                 image.EndInit();                 bitmap.Dispose();                 GC.Collect();                 if (!image.IsFrozen && image.CanFreeze)                 {                     image.Freeze();                 }                 return image;             }             return null;         }         public static Bitmap ReplaceColor(Bitmap bitmap, Color toReplace, Color replacement, int threshold)         {             unsafe             {                 BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);                 int bytesPerPixel = System.Drawing.Image.GetPixelFormatSize(bitmap.PixelFormat) / 8;                 int heightInPixels = bitmapData.Height;                 int widthInBytes = bitmapData.Width * bytesPerPixel;                 byte* ptrFirstPixel = (byte*)bitmapData.Scan0;                 Parallel.For(0, heightInPixels, y =>                 {                     byte* sourceRow = ptrFirstPixel + (y * bitmapData.Stride);                     byte* targetRow = ptrFirstPixel + (y * bitmapData.Stride);                     for (int x = 0; x < widthInBytes; x += bytesPerPixel)                     {                         byte b = sourceRow[x + 0];                         byte g = sourceRow[x + 1];                         byte r = sourceRow[x + 2];                         if (toReplace.R - threshold <= r && toReplace.G - threshold <= g && toReplace.B - threshold <= b)                         {                             r = replacement.R;                             g = replacement.G;                             b = replacement.B;                         }                         targetRow[x + 0] = b;                         targetRow[x + 1] = g;                         targetRow[x + 2] = r;                     }                 });                 bitmap.UnlockBits(bitmapData);             }             return bitmap;         }         [DllImport("gdi32.dll")]         [return: MarshalAs(UnmanagedType.Bool)]         internal static extern bool DeleteObject(IntPtr value);         private void Button_Click(object sender, RoutedEventArgs e)         {             openFileDialog = new OpenFileDialog { Multiselect = false, Filter = "Image Files(*.PNG; *.JPG; *.BMP)| *.PNG; *.JPG; *.BMP | All files(*.*) | *.*" };             if (openFileDialog.ShowDialog() == true)             {                 using (Bitmap bitmap = new Bitmap(openFileDialog.FileName))                 {                     Img.Source = GetImageStream(bitmap,ImageFormat.Jpeg);                 }             }         }         private void Grid_PreviewMouseMove(object sender, MouseEventArgs e)         {             VisualBrush b = (VisualBrush)rct.Fill;             System.Windows.Point pos = e.MouseDevice.GetPosition(this);             Rect viewBox = b.Viewbox;             double xoffset = viewBox.Width / 2.0;             double yoffset = viewBox.Height / 2.0;             viewBox.X = pos.X - xoffset;             viewBox.Y = pos.Y - yoffset;             b.Viewbox = viewBox;             Canvas.SetLeft(cnv, pos.X - (rct.Width / 2));             Canvas.SetTop(cnv, pos.Y - (rct.Height / 2));         }         private void Img_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)         {             Renk = GeçiciRenk;             MessageBox.Show($"Renk Seçildi {Renk} Eşik Değeri Ayarlayın.", "Renk");         }         private void Img_MouseMove(object sender, MouseEventArgs e)         {             try             {                 CroppedBitmap cb = new CroppedBitmap(Img.Source as BitmapSource, new Int32Rect((int)((int)e.GetPosition(Img).X * ((BitmapSource)Img.Source).PixelWidth / Img.ActualWidth), (int)((int)e.GetPosition(Img).Y * ((BitmapSource)Img.Source).PixelWidth / Img.ActualWidth), 1, 1));                 pixels = new byte[4];                 try                 {                     cb.CopyPixels(pixels, 4, 0);                 }                 catch (Exception ex)                 {                     MessageBox.Show(ex.Message);                 }                 GeçiciRenk = System.Windows.Media.Color.FromRgb(pixels[2], pixels[1], pixels[0]);             }             catch (Exception)             {             }         }         private void Sld_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)         {             if (openFileDialog != null)             {                 using (var convertedbitmap = new Bitmap(openFileDialog.FileName))                 {                     using (Bitmap bitmap = ReplaceColor(convertedbitmap, Color.FromArgb(Renk.R, Renk.G, Renk.B), Color.White, (int)Sld.Value))                     {                         Img2.Source = GetImageStream(bitmap,ImageFormat.Jpeg);                     }                 }             }         }     } }



    < Bu mesaj bu kişi tarafından değiştirildi Gökşen PASLI -- 9 Şubat 2021; 22:7:1 >




  • Gökşen PASLI G kullanıcısına yanıt

    Emeğiniz için çok teşekkür ederim. Evet sanırım pek performans alamayacağız. Ama yine de bu yöntemi deneyeceğim. Sanırım tek tip evrak olması nedeniyle biraz işe yarayacak gibi görünüyor. Tekrar teşekkür ederim. Üzerinde çalışıp geliştireceğim sonucu burada paylaşmayı ümit ediyorum.

  • 
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.