kmp*_*kmp 6 .net c# twain opencv emgucv
我正在使用Epson Perfection V700扫描仪,并在使用他们的工具进行扫描时选择以下选项:
这会产生这样的图像:

现在我的问题是 - 我实际上需要使用TWAIN .Net与此扫描仪进行交互,当我这样做时,我得到的图像是这样的:

旁白:我取消选择前面提到的两个选项并再次使用Epson进行扫描,得到的图像非常类似于我通过TWAIN获得的图像.
所以我认为也许这些是我可以在图像上自己完成的后期处理步骤(也许它们是以某种方式在硬件中完成的,我不知道).
我正在使用EmguCV,所以我首先创建了一个应用ICM的扩展方法(我很难找到这个的任何文档,所以这是一个猜测,也许我马上就错了,但我从这里得到的信息:位图转换类似乎对图像产生了影响):
public static Image<Bgr, TDepth> ApplyIcm<TDepth>(
this Image<Bgr, TDepth> source,
string sourceIcm,
string targetIcm)
where TDepth : new()
{
var target = source.CopyBlank();
using (source)
{
using (var b = source.Bitmap)
{
using (var memory = new MemoryStream())
{
b.Save(memory, ImageFormat.Bmp);
memory.Position = 0;
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
var ccb = new ColorConvertedBitmap();
ccb.BeginInit();
ccb.Source = bitmapImage;
ccb.SourceColorContext =
new ColorContext(new Uri(sourceIcm));
ccb.DestinationColorContext =
new ColorContext(new Uri(targetIcm));
ccb.EndInit();
var encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(ccb));
using (var ms = new MemoryStream())
{
encoder.Save(ms);
target.Bitmap = new Bitmap(ms);
}
}
}
}
return target;
}
Run Code Online (Sandbox Code Playgroud)
然后我看着那个不起眼的东西,遇到了这个问题: 如何在OpenCV中锐化图像?其中说:
您使用高斯平滑滤镜并从原始图像中减去平滑后的版本
(我还检查了这个问题,找出等效的emgucv调用是什么为什么EmguCV高斯模糊不能返回与OpenCV高斯模糊相同的结果?)并提出了这个额外的扩展方法:
public static Image<Bgr, TDepth> UnsharpMask<TDepth>(
this Image<Bgr, TDepth> source,
Size kernelSize,
int kernelHoritonalStandardDeviation,
int kernelVerticalStandardDeviation,
double alpha,
double beta,
double gamma)
where TDepth : new()
{
Image<Bgr, TDepth> ret = source.CopyBlank();
CvInvoke.cvSmooth(source,
ret,
SMOOTH_TYPE.CV_GAUSSIAN,
kernelSize.Width,
kernelSize.Height,
kernelHoritonalStandardDeviation,
kernelVerticalStandardDeviation);
CvInvoke.cvAddWeighted(source, alpha, ret, beta, gamma, ret);
return ret;
}
Run Code Online (Sandbox Code Playgroud)
现在我称之为:
string sourceIcm = @"C:\Windows\System32\spool\drivers\color\ewrgb18.icm";
string targetIcm = @"C:\Windows\System32\spool\drivers\color\ewsrgb.icm";
using(var im = new Image<Bgr, byte>("out.bmp"))
{
using (var icmmed = im.ApplyIcm(sourceIcm, targetIcm))
{
using (var ret = icmmed.UnsharpMask(new Size(0, 0), 5, 5, 2.4, -1.5, 0))
{
ret.Save("ret.bmp");
}
}
}
Run Code Online (Sandbox Code Playgroud)
这就是结果:

不是很好!:-(
我无休止地摆弄参数,但我无法弄清楚我是如何(或者甚至)能够获得与Epson工具相同的结果.
所以,我的问题是:
有没有人知道是否有可能使用opencv/emgucv(甚至是TWAIN - 我仔细查看了文档并尝试调整了一些功能参数,但我只是让图像变得更糟)才能获得结果,这与锐度相似到上面的原始图像或是否有我应该尝试的另一种技术(可能是我需要知道有关硬件本身的一些细节才能实现正确的锐化)?
| 归档时间: |
|
| 查看次数: |
1851 次 |
| 最近记录: |