linq

c#数字图像处理(二)彩色图像灰度化,灰度图像二值化

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-16 19:34:01
为加快处理速度,在图像处理算法中,往往需要把彩色图像转换为灰度图像,在灰度图像上得到验证的算法,很容易移 植到彩色图像上。 24位彩色图像每个像素用3个字节表示,每个字节对应着R、G、B分量的亮度(红、绿、蓝)。当R、G、B分量值不同时,表现为彩色图像;当R、G、B分量值相同时,表现为灰度图像,该值就是我们所求的一般来说,转换公式有3种。第一种转换公式为: Gray(i,j)=[R(i,j)+G(i,j)+B(i,j)]÷3            (2.1) 其中,Gray(i,j)为转换后的灰度图像在(i,j)点处的灰度值。该方法虽然简单,但人眼对颜色的感应是不同的,因此有了第二种转换公式: Gray(i,j)=0299R(i,j)+0.587×G(i,j)+0.114×B(i,j)      (2.2) 观察上式,发现绿色所占的比重最大,所以转换时可以直接使用G值作为转换后的灰度 Gray(i,j)=G(i,j)                    (2.3) 在这里,我们应用最常用的公式(2.2),并且变换后的灰度图像仍然用24位图像表示。 1.提取像素法 这种方法简单易懂,但相当耗时,完全不可取. 该方法使用的是GD+中的 Bitmap Getpixel和 BitmapSetpixel.方法。为了将位图的颜色设置为灰度或其他颜色,就需要使用

LINQ contains one match from array of strings

北慕城南 提交于 2021-02-16 16:01:48
问题 Having trouble getting this to work: /// <summary> /// Retrieve search suggestions from previous searches /// </summary> public static string[] getSearchSuggestions(int SectionID, string Query) { string[] Suggestions; string[] Words = Query.Split(' '); using (MainContext db = new MainContext()) { Suggestions = (from c in db.tblSearches where c.SectionID == SectionID && Words.Any(w => c.Term.Contains(w)) select c.Term).ToArray(); } return Suggestions; } I get: System.NotSupportedException:

LINQ contains one match from array of strings

核能气质少年 提交于 2021-02-16 16:01:41
问题 Having trouble getting this to work: /// <summary> /// Retrieve search suggestions from previous searches /// </summary> public static string[] getSearchSuggestions(int SectionID, string Query) { string[] Suggestions; string[] Words = Query.Split(' '); using (MainContext db = new MainContext()) { Suggestions = (from c in db.tblSearches where c.SectionID == SectionID && Words.Any(w => c.Term.Contains(w)) select c.Term).ToArray(); } return Suggestions; } I get: System.NotSupportedException:

LINQ Select Syntax VB.NET

一曲冷凌霜 提交于 2021-02-16 15:59:34
问题 I have a list of Tuples I am trying to run a Select and Where query on to return a list of Objects from the Tuple.Item5 parameter. In my where clause I am looking to match Tuple.Item4 to a local variable. I'm not sure what the VB.NET syntax is for the Select portion, I only know the c# syntax. Essentially I am trying to select Tuple.Item5 from my list of tuples where Tuple.Item4 = sCurID. I'm unsure as to what should go in the Select section although in c# I believe it would be Select(t => t

Declaring explicit type instead of var in select statement

时光怂恿深爱的人放手 提交于 2021-02-16 14:20:34
问题 I'm doing the following request. It works as supposed to and returns data structured correctly. (It creates an element with "head" corresponding to the common field and puts the all elements of the same value in that field as a an Array in the "tail".) var result = from A in As group A by A.F into B select new { F1 = B.Key, F2 = from A in As where A.F == B.Key select A }; Now I'd like to declare it's type explicitly. I've checked in the debugger that my assumption on types is correct, however

LINQ deferred (or immediate?) execution

♀尐吖头ヾ 提交于 2021-02-16 14:20:31
问题 Given the following query: List<GetMultipleLookupListsOutput> data = await _masterListTranslationsRepository .GetAll() //<- it returns IQueriable .GroupBy(q => q.ListLabelID) .Select(q => q .OrderByDescending(w=>w.ISOLanguageCode == isoLanguageCode) .ThenByDescending(w=>w.ISOLanguageCode == "en-US")) .Select(q => q.FirstOrDefault()) // DB call ? .GroupBy(q=>q.ListLabels.Lists.ListName) .Select(q => new GetMultipleLookupListsOutput { ListName = q.Key, LookupLists = q .OrderByDescending(w => w

Lambda表达式动态组装查询条件

删除回忆录丶 提交于 2021-02-13 07:37:34
最近比较闲,年底了,项目也进入尾声;每天就是维护一下系统,整理整理文档,整理知识点,这样才觉得有点意思; 问题 在使用Linq的where()查询的时候,不知道大家是怎么动态组装多个查询条件时,是怎么做的?我是这样做的,请看下面代码; 方法一: 1.1 Expression的扩展类 public static class PredicateExtensions { public static Expression<Func<T, bool>> True<T>() { return f => true; } public static Expression<Func<T, bool>> False<T>() { return f => false; } public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expression1, Expression<Func<T, bool>> expression2) { var invokedExpression = Expression.Invoke(expression2, expression1.Parameters.Cast<Expression>()); return Expression.Lambda<Func<T, bool>>

Lambda查询

放肆的年华 提交于 2021-02-13 07:31:00
使用EF查询数据库,之前使用Linq表达式,现在改成另一个种方法查询:Lambda表达式 TestEntities db= new TestEntities(); var userinfo = db.UserInfo.Where<UserInfo>(u => u.ID == 1 ).FirstOrDefault(); 其中Where方法是扩展方法。 public static IQueryable<TSource> Where<TSource>( this IQueryable<TSource> source, Expression<Func<TSource, bool >> predicate); 扩展方法的第一个参数前必须加this关键字, 紧跟着是类型表示这个方法是给哪个类型扩展的。 后面的参数才表示调用这个方法的时候传的参数。 在第二个参数中, Expression表示Lambda表达式树。 Func<TSource, bool>是委托,需要一个 TSource类型的委托,结果返回bool类型。 // public delegate int AddSum(int a, int b); static void Main( string [] args) { Program p = new Program(); // AddSum addSum = new AddSum(p

C# 多线程 用委托实现异步_调用委托的BeginInvoke和EndInvoke方法

北城以北 提交于 2021-02-12 18:49:06
C# 多线程 用委托实现异步_调用委托的BeginInvoke和EndInvoke方法 1.C#中的每一个委托都内置了BeginInvoke和EndInvoke方法,如果委托的方法列表里只有一个方法,那么这个方法就可以异步执行(不在当前线程里执行,另开辟一个线程执行)。委托的BeginInvoke和EndInvoke方法就是为了上述目的而生的。 2.原始线程发起了一个异步线程,有如下三种执行方式: 方式一:等待一直到完成,即原始线程在发起了异步线程以及做了一些必要处理之后,原始线程就中断并等待异步线程结束再继续执行。 方式二:轮询,即原始线程定期检查发起的线程是否完成,如果没有则可以继续做一些其它事情。 方式三:回调,即原始线程一直执行,无需等待或检查发起的线程是否完成。在发起的线程执行结束,发起的线程就会调用用户定义好的回调方法,由这个回调方法在调用EndInvoke之前处理异步方法执行得到的结果。 3.一个控制台小程序,使用了上面三种方式,执行结果如下: 4.代码: 1 [csharp] view plain copy 2 3 using System; 4 using System.Collections.Generic; 5 using System.Linq; 6 using System.Runtime.Remoting.Messaging; 7 using

[C#基础]c#中的BeginInvoke和EndEndInvoke

余生颓废 提交于 2021-02-12 15:25:36
摘要 异步这东西,真正用起来的时候,发现事情还是挺多的,最近在项目中用到了异步的知识,发现对它还是不了解,处理起来,走了不少弯路。觉得还是补一补还是很有必要的。 MSDN原文地址:https://msdn.microsoft.com/en-us/library/2e08f6yc(v=vs.110).aspx 正文 .Net framework可以让你异步调用任何方法。为达这样的目的,你可以定义一个与你要调用的方法的签名相同的委托。公共语言运行时将自动为该委托定义与签名相同的BeginInvok和EndInvoke方法。 异步委托调用BeginInvok和EndInvoke方法,但在.NET Compact Framework中并不支持。 BeginInvoke方法触发你的异步方法,它和你想要执行的异步方法有相同的参数。另外还有两个可选参数,第一个是AsyncCallback委托是异步完成的回调方法。第二个是用户自定义对象,该对象将传递到回调方法中。BeginInvoke立即返回并且不等待完成异步的调用(继续执行该下面的代码,不需要等待)。BeginInvoke返回IAsyncResult接口,可用于检测异步调用的过程。 通过EndInvoke方法检测异步调用的结果。如果异步调用尚未完成,EndInvoke将阻塞调用线程,直到它完成。EndInvoke参数包括out和ref参数。