需要转换这部分C#代码 [英] Need to transfrm this part of C# code

查看:89
本文介绍了需要转换这部分C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新用户(也是programin中的新用户),我正在创建一个程序以并行方式逐像素比较两个图像,并且我需要任何人的帮助才能从串行方式并行转换这部分C#代码.该程序适用于我在学校的子喷气机.代码是:

I am a new user (also new in programin), I am creating a program to compare two images pixel by pixel in parallel form, and I need help from anyone to transform this part of C# code from serial form in parallel. This program is for my subjet in school. The code is:

for (int pikselat_ne_rresht = 0; pikselat_ne_rresht < a.Width; pikselat_ne_rresht++)
{
    for (int pikselat_ne_kolon = 0; pikselat_ne_kolon < a.Height; pikselat_ne_kolon++)
    {
        if (a.GetPixel(pikselat_ne_rresht, pikselat_ne_kolon) == b.GetPixel(pikselat_ne_rresht, pikselat_ne_kolon))
        {
            //Rezultati.SetPixel(pikselat_ne_rresht, pikselat_ne_kolon, mire);
            pikselat_e_njejet++;
        }
        else
        {
            b.SetPixel(pikselat_ne_rresht, pikselat_ne_kolon, gabim);
            //Rezultati.SetPixel(pikselat_ne_rresht, pikselat_ne_kolon, gabim);
            pikselat_e_ndryshem++;
            te_njejta = false;
        }
    }
}


或者,如果有人拥有这样的程序并愿意与我(和其他人)共享,我会很乐意.我将尽快等待淀粉样蛋白的回复.祝一切顺利.


Or if someone have such a program and would share with me (and others)i will be gearful. I will wait for some reply fro amyone as soon as posible. All the best from me.

推荐答案



阅读此文章:
C#中的并行计算 [通过C#4.0进行并行计算的概念 [ .NET 4.0并行编程简介 [ http://www.google.com/search?q=parallel+programming+c%23 [^ ]
另外,请参阅并行编程"文章:
http://www.codeproject.com/KB/Parallel_Programming/ [
Hi,

Read this articles:
Parallel Computations in C#[^]
Parallel Computing Concepts via C# 4.0[^]
Introducing .NET 4.0 Parallel Programming[^]

I found all articles here:
http://www.google.com/search?q=parallel+programming+c%23[^]
Also, have a look at the "Parallel programming" articles:
http://www.codeproject.com/KB/Parallel_Programming/[^]


有关方法的详细讨论和定时比较比较两个大小相同的图像...通过逐字节(int),通过md5(哈希),通过掩码,通过使用lockbits调用msvcrt.dll中的memcmp函数...

...假设您没有旋转,没有翻转并且两个图像都具有相同的格式,例如:Format32bppRgb ... ...带有C#代码完成...请参阅:[
^ ]

关于其他与您可能不相关的问题的猜测:

尝试解决这样的问题时,尽可能了解所比较内容的内容"中可能存在的差异是有帮助的.如果根本无法预测方差:您的解决方案当然必须更笼统.

此问题的一个重要方面是:是否必须处理两张不同大小的图片 ,其中包含相同数量的像素(可能是相同的),但是一张图片已经旋转和/或翻转.

现在,您是否可以期望仅通过查找图像尺寸上的差异,就可以自动拒绝比较400x300图像和300x400图像?还是您必须处理这些情况?

比较两张图片,它们的像素总数匹配,但是它们的相对大小排除了其中一幅,而另一幅则是另一幅的变换(旋转,翻转):您需要处理这种情况吗?

因此,请考虑两张图片,如上例所示,它们的大小不相同,但如果将一张图片旋转90度或-90度,则匹配.您需要处理这种情况吗?

而且,如果它们的大小相同,但是一幅图像已在水平或垂直方向上翻转了180度.如果一个人既旋转又翻转"怎么办?您是否需要处理此类情况?
For a detailed discussion, and timed comparisons, of ways of comparing two identically sized images ... via byte-by-byte (ints), via md5 (hash), via mask, via calling memcmp function in msvcrt.dll, using lockbits ...

... where you assume no rotation, no flipping, and that both images are in an identical format, for example: Format32bppRgb ... ... complete with C# code ... see: [^]

Speculation on other issues that may not be relevant to you:

When trying to solve a problem like this, it is helpful to know as much as possible about the possible variance in "content" of whatever it is you are comparing. If the variance can''t be predicted at all: your solution must be, of course, more general.

An important aspect in this problem is: whether you are going to have to deal with two pictures of different sizes that contain the same number of pixels, which may be, possibly, identical, but one picture has been rotated and/or flipped.

Can you expect, now, that by simply looking for differences in image dimensions, you can automatically reject comparing, for example, a 400x300 image with a 300x400 image ? Or do you have to handle those cases ?

The case of comparing two pictures where the total number of pixels match but their relative sizes preclude one being a transformation (rotation, flipping) of the other: do you need to handle such cases ?

So: consider two pictures whose sizes, as in the example above, are not identical but match if one picture is rotated either 90 or -90 degrees. Do you need to handle such cases ?

And what, if they are the same size, but one image has been flipped 180 degrees horizontally or vertically. What if one has been both rotated and "flipped" ? Do you need to handle such cases ?


请参阅我对问题的评论;不要使用GetPixel/SetPixel.如果是System.Drawing,则需要使用System.Drawing.Bitmap.LockBits:
http://msdn.microsoft.com/en-us/library/system. drawing.bitmap.lockbits.aspx [ ^ ].

这两个功能中的第一个的MSDN帮助页面包含一个简短的代码示例.

—SA
Please see my comment to the question; don''t use GetPixel/SetPixel. If this is System.Drawing, you need to use System.Drawing.Bitmap.LockBits:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx[^].

The MSDN help page of first of these two functions contains a short code sample.

—SA


这篇关于需要转换这部分C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆