mehrdad1991h
یک شنبه 27 بهمن 1392, 11:55 صبح
سلام
خوب یه تصویر داریم توش خط و نقطه زیادی هست (همون نویز)
میخوام این نویز ها را پاک کنم
چه میکنیم ؟
در ضمن تصویر سیاه و سفید هست (مزیت ما که البته با توجه به کد من فرقی هم نداره)
کاری که من میکنم
میام تصویر را ماتریکس بندی میکنم
بعد هر خونه را چک میکنم ببینم چی توشه و نویز ها را پاک میکنیم
حالا بگیرید پاک هم شد بعد موقع سیو هنگ میکنه خطا میده نمیتونه سیو کنه
کدی هم که من استفاده میکنم این زیر گذاشتم (چک کنید)
حالا یه کاری میخوام بکنم که این نویز ها پاک بشه من چه کنم که این عملی بشه چیزی به ذهن شما نمیرسه ؟
تو این اینترنت هم ما هرچی گشتیم هیچی نیست یه فیلم فقط پیا کردیم که اونم کدهاش مشخص نبود چجوریه همین یه تصویر میداد و خروجی میگرفت کد مد نداشت که بشه چک کرد چیکار میکنه !
لطفا اگر کسی نمونه چیزی راه حلی کمیک هر چیزی هست لطفا دریق نکنه من تو همین یه تیکه اش موندم
public static Bitmap RemoveNoise(Bitmap original, int level, int radius)
{
int width = original.Width;
int height = original.Height;
Bitmap source = null;
source = original.PixelFormat != PixelFormat.Format8bppIndexed
?
Make(original)
: original;
Bitmap destination = GrayscaleImage(width, height);
BitmapData srcData = source.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly,
source.PixelFormat);
BitmapData dstData = destination.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly,
destination.PixelFormat);
int stride = srcData.Stride;
byte pxVal;
int matrixWidth = (radius * 2 + 1) * (radius * 2 + 1);
var pxM = new byte[matrixWidth];
int meanIndex = (matrixWidth - 1) / 2;
unsafe
{
var srcScan0 = (byte*)srcData.Scan0;
var dstScan0 = (byte*)dstData.Scan0;
for (int l = 0; l < level; l++)
{
for (int y = radius; y < height - radius; y++)
{
byte* srcRow = srcScan0 + (y * stride);
byte* dstRow = dstScan0 + (y * stride);
for (int x = radius; x < width - radius; x++)
{
pxVal = srcRow[x];
int mIndex = 0;
for (int k = y - radius; k < y + radius + 1; k++)
{
byte* srcRowMatrix = srcScan0 + (k * stride);
for (int j = x - radius; j < x + radius + 1; j++)
{
pxM[mIndex++] = srcRowMatrix[j];
}
}
Array.Sort(pxM);
dstRow[x] = pxM[meanIndex];
}
}
}
}
destination.UnlockBits(dstData);
source.UnlockBits(srcData);
if (source != original)
source.Dispose();
return destination;
}
public static Bitmap Make(Bitmap original)
{
Bitmap newBitmap = new Bitmap(original.Width, original.Height);
for (int i = 0; i < original.Width; i++)
{
for (int j = 0; j < original.Height; j++)
{
Color originalColor = original.GetPixel(i, j);
int grayScale = (int)((originalColor.R * .3) + (originalColor.G * .59)
+ (originalColor.B * .11));
Color newColor = Color.FromArgb(grayScale, grayScale, grayScale);
newBitmap.SetPixel(i, j, newColor);
}
}
return newBitmap;
}
public static Bitmap GrayscaleImage(int width, int height)
{
Bitmap image = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
SetGrays(image);
return image;
}
public static void SetGrays(Bitmap image)
{
ColorPalette cp = image.Palette;
for (int i = 0; i < 256; i++)
{
cp.Entries[i] = Color.FromArgb(i, i, i);
}
image.Palette = cp;
}
خوب یه تصویر داریم توش خط و نقطه زیادی هست (همون نویز)
میخوام این نویز ها را پاک کنم
چه میکنیم ؟
در ضمن تصویر سیاه و سفید هست (مزیت ما که البته با توجه به کد من فرقی هم نداره)
کاری که من میکنم
میام تصویر را ماتریکس بندی میکنم
بعد هر خونه را چک میکنم ببینم چی توشه و نویز ها را پاک میکنیم
حالا بگیرید پاک هم شد بعد موقع سیو هنگ میکنه خطا میده نمیتونه سیو کنه
کدی هم که من استفاده میکنم این زیر گذاشتم (چک کنید)
حالا یه کاری میخوام بکنم که این نویز ها پاک بشه من چه کنم که این عملی بشه چیزی به ذهن شما نمیرسه ؟
تو این اینترنت هم ما هرچی گشتیم هیچی نیست یه فیلم فقط پیا کردیم که اونم کدهاش مشخص نبود چجوریه همین یه تصویر میداد و خروجی میگرفت کد مد نداشت که بشه چک کرد چیکار میکنه !
لطفا اگر کسی نمونه چیزی راه حلی کمیک هر چیزی هست لطفا دریق نکنه من تو همین یه تیکه اش موندم
public static Bitmap RemoveNoise(Bitmap original, int level, int radius)
{
int width = original.Width;
int height = original.Height;
Bitmap source = null;
source = original.PixelFormat != PixelFormat.Format8bppIndexed
?
Make(original)
: original;
Bitmap destination = GrayscaleImage(width, height);
BitmapData srcData = source.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly,
source.PixelFormat);
BitmapData dstData = destination.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly,
destination.PixelFormat);
int stride = srcData.Stride;
byte pxVal;
int matrixWidth = (radius * 2 + 1) * (radius * 2 + 1);
var pxM = new byte[matrixWidth];
int meanIndex = (matrixWidth - 1) / 2;
unsafe
{
var srcScan0 = (byte*)srcData.Scan0;
var dstScan0 = (byte*)dstData.Scan0;
for (int l = 0; l < level; l++)
{
for (int y = radius; y < height - radius; y++)
{
byte* srcRow = srcScan0 + (y * stride);
byte* dstRow = dstScan0 + (y * stride);
for (int x = radius; x < width - radius; x++)
{
pxVal = srcRow[x];
int mIndex = 0;
for (int k = y - radius; k < y + radius + 1; k++)
{
byte* srcRowMatrix = srcScan0 + (k * stride);
for (int j = x - radius; j < x + radius + 1; j++)
{
pxM[mIndex++] = srcRowMatrix[j];
}
}
Array.Sort(pxM);
dstRow[x] = pxM[meanIndex];
}
}
}
}
destination.UnlockBits(dstData);
source.UnlockBits(srcData);
if (source != original)
source.Dispose();
return destination;
}
public static Bitmap Make(Bitmap original)
{
Bitmap newBitmap = new Bitmap(original.Width, original.Height);
for (int i = 0; i < original.Width; i++)
{
for (int j = 0; j < original.Height; j++)
{
Color originalColor = original.GetPixel(i, j);
int grayScale = (int)((originalColor.R * .3) + (originalColor.G * .59)
+ (originalColor.B * .11));
Color newColor = Color.FromArgb(grayScale, grayScale, grayScale);
newBitmap.SetPixel(i, j, newColor);
}
}
return newBitmap;
}
public static Bitmap GrayscaleImage(int width, int height)
{
Bitmap image = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
SetGrays(image);
return image;
}
public static void SetGrays(Bitmap image)
{
ColorPalette cp = image.Palette;
for (int i = 0; i < 256; i++)
{
cp.Entries[i] = Color.FromArgb(i, i, i);
}
image.Palette = cp;
}