473,410 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Fast way to put image into rgb-matrix (vb.net)

Hello,

I am using a 2-dimensional matrix for image manipulation and recognition.
The x-axes is image.width pixels long and the y-axes image.height.
All fields have a RGB integer value.
To store this value from the image into the matrix I am using the
bitmap.getPixel(x,y) method because manipulating values in the matrix is
much faster than using the bitmap.setPixel(x,y,color) method.
My problem is, that the getPixel function is also very slow.
Is there a way to get the RGB values from the picture more easily?

Thanks,

Harry

P.S: the matrix looks like:
[RGB_11,RGB_12,....,RGB_1n]
[RGB_21,RGB_22,....,RGB_2n]
....
[RGB_n1,RGB_n2,....,RGB_nn]
Nov 20 '05 #1
4 21241
Hi Harry,

How are you with C ?

You could put the need-for-speed processing in a C# library using 'unsafe'
pointer manipulation. The following article gives the pros and cons plus a
sample which converts a colour bitmap to grey-scale.
http://msdn.microsoft.com/library/de.../dncscol/html/
csharp11152001.asp

If that doesn't appeal, GetPixel() is sooo slooow, that it might be
quicker to write your bitmap to a MemoryStream, read it back into an array,
fiddle with the array and the reverse back into your bitmap.

Good luck,

Regards,
Fergus
Nov 20 '05 #2

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...
Hi Harry,

How are you with C ?

You could put the need-for-speed processing in a C# library using 'unsafe' pointer manipulation. The following article gives the pros and cons plus a
sample which converts a colour bitmap to grey-scale.


When I posted a similar topic to the Preformance group (asking if C++ would
execute faster given a standard algorithm), one of the guys from MS JIT
compiler team was saying that there is no way C++/C would be faster than
..NET unless you made the GC to work overtime. I thought that was wierd, but
he was very insistant that the IL code should execute just as fast as the
C/C++ native ASM...
~
Jeremy

Nov 20 '05 #3
"Harry" <le****@gmx.net> wrote in message
news:10***************@news.aic.at...
Hello,

I am using a 2-dimensional matrix for image manipulation and recognition.
The x-axes is image.width pixels long and the y-axes image.height.
All fields have a RGB integer value.
To store this value from the image into the matrix I am using the
bitmap.getPixel(x,y) method because manipulating values in the matrix is
much faster than using the bitmap.setPixel(x,y,color) method.
My problem is, that the getPixel function is also very slow.
Is there a way to get the RGB values from the picture more easily?


This is really a question for the dotnet.Framework.Drawing group, but I
might know a way to speed things up; Have you tried using the LockBits( )
function on the bitmaps? It will return a 1 dimensional array of values in
the current bitmap format. The array looks like this (depending on the
bitmap format):

{r,g,b,r,g,b,r,g,b,r,g,b}

By reading the properties of the BitmapData structure, you can determine how
to loop through the structure so you get one pixel each pass (stepping).
Here is some code I was playing with to invert an image (it is hard-coded
for 32bpp ARGB, and will convert your buffer image to this format
[bmpBuffer]):
'-------------------------------8<----------------------------
'// warning: this is not optimised at all!
'
Sub Invert(bmpBuffer as Bitmap)
Dim bts As Drawing.Imaging.BitmapData
Dim b() As Byte
Dim Y, iBDIndex, X As Integer
Dim bmTemp As New Bitmap(bmpBuffer.Width, bmpBuffer.Height, _
Drawing.Imaging.PixelFormat.Format32bppRgb)

Dim g As Graphics = Graphics.FromImage(bmTemp)

ReDim b((bmpBuffer.Width * 4) * (bmpBuffer.Height))

g.DrawImage(bmpBuffer, 0, 0)
g.Dispose()

bts = bmTemp.LockBits(New Rectangle(0, 0, bmpBuffer.Width, _
bmpBuffer.Height), Drawing.Imaging.ImageLockMode.ReadWrite, _
Drawing.Imaging.PixelFormat.Format32bppArgb)

Runtime.InteropServices.Marshal.Copy(bts.Scan0, b, 0,
((bmpBuffer.Width) * 4) _
* (bmpBuffer.Height))

iBDIndex = 0

'// divides by 4, and steps by 4 because it is ARGB 32bpp

For Y = 0 To (bmpBuffer.Height - 1)
For X = 0 To ((UBound(b) / 4) / (bmpBuffer.Height)) - 1
b(iBDIndex) = Not b(iBDIndex)
b(iBDIndex + 1) = Not b(iBDIndex + 1)
b(iBDIndex + 2) = Not b(iBDIndex + 2)
iBDIndex += 4
Next
Next

Runtime.InteropServices.Marshal.Copy(b, 0, bts.Scan0, _
((bmpBuffer.Width) * 4) * (bmpBuffer.Height))

bmTemp.UnlockBits(bts)

picMain.Image.Dispose()
bmpBuffer.Dispose()
bmpBuffer = New Bitmap(bmTemp)
bmTemp.Dispose()
End Sub
'-------------------------------8<----------------------------

A good site for drawing is http://www.vbaccelerator.com/ and the Drawing
newsgroup (microsoft.public.dotnet.framework.drawing).

HTH,
Jeremy

Nov 20 '05 #4
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
You could put the need-for-speed processing in a C#
library using 'unsafe' pointer manipulation. The following article
gives the pros and cons plus a sample which converts a
colour bitmap to grey-scale.

http://msdn.microsoft.com/library/de.../dncscol/html/ csharp11152001.asp


Additional information:

Part 1: http://www.codeproject.com/cs/media/...cfilters11.asp
Part 2: http://www.codeproject.com/cs/media/csharpfilters.asp
Part 3: http://www.codeproject.com/cs/media/edge_detection.asp
Part 4: http://www.codeproject.com/cs/media/...rocessing4.asp
Part 5: http://www.codeproject.com/cs/media/...entFilters.asp

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrew Crowe | last post by:
Hi guys, We've got a content management system in PHP that allows users to upload images that are resized and sharpened. The resizing is done using the GD libraries resampling function and to...
0
by: Mark McKay | last post by:
I will be starting a contract with a film production company soon, and will be writing code to process large images representing frames of movies (unknown file format at this time). I'd also like...
0
by: csgraham74 | last post by:
Hello, Ive created a datagrid and inserted a table for displaying images. i have four small images and one large image. I want to replace the large image with the small image when i...
2
by: eSolTec, Inc. 501(c)(3) | last post by:
I'm looking for code samples to send a jpg image from a client machine to a host machine. Both have the same image picWindows picture container. I would like to be able to send the image on one...
0
by: George Harris | last post by:
I made an application for Image Windowing where the contrast/ brigtness of the image can be controlled. It takes around 4 seconds for a 256 * 256 to load the image using Panel Tool. My requirement...
15
by: Michael A. Covington | last post by:
Any thoughts about how to implement image processing algorithms to run fast in C#? Using GetPixel to access every pixel from a Bitmap seems to be rather time-consuming.
0
by: adubra | last post by:
Hi there, I am using a device context (DC) and a buffer to successfully draw to screen. However, when I update the DC at very high frame rate and drag the frame containing the image very quickly...
2
by: papillonhn | last post by:
Please, help me. I'm using asp.net 2.0. I have a problem that: I have an weather background image. I need to add texts (like temperature) and 'icon images' (like rainy, sunny ..) on background...
0
by: Peter Morris | last post by:
A while ago I asked how to replace an image with a solid black colour whilst preserving the alpha mask/channel, this was so that I could automatically create a drop shadow. For future reference of...
2
by: mihirihp | last post by:
How to transfer image using .Net Remoting from Server application to Client in C#.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.