-
Oct 13th, 2013, 05:51 AM
#41
Re: FastPix: Rapid Pixel Processing for Dummies and Dudes
Originally Posted by supray
Hi
does PixelArray retrun a array for each horizontal row of the image ?
No, it just returns a single array for the whole image. This is for reasons of efficiency: one dimensional arrays are quite a bit faster to index than two dimensional arrays. In your code, you are mixing up the two approaches. If you are using PixelArray you would normally calculate the index as y * bitmap.Width + x. But FastPix.GetPixel and SetPixel do that calculation for you. So you could change your loop to this:
Code:
Using fp As New FastPix(b)
For x As Integer = 0 To b.Width - 1 Step 20
For y As Integer = 0 To b.Height - 1 Step 20
fp.SetPixel(x, y, Color.Orange)
Next
Next
End Using
PictureBox2.Image = b
The Step value above gives the pixel spacing of the grid lines, so I guess you want something less than 200 pixels!
By the way, Graphics commands like DrawLine and DrawImage don't have the efficiency drawbacks of Bitmap.SetPixel and Bitmap.GetPixel. So you might consider drawing your grid in the Paint sub of the PictureBox, instead of using FastPix. It wouldn't surprise me if it was even more efficient. For example:
Code:
Private Sub PictureBox1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Using pn As New Pen(Brushes.Orange)
pn.DashStyle = Drawing2D.DashStyle.Dot
For x As Integer = 0 To PictureBox1.Width Step 20
e.Graphics.DrawLine(pn, x, 0, x, PictureBox1.Height)
Next
For y As Integer = 0 To PictureBox1.Height Step 20
e.Graphics.DrawLine(pn, 0, y, PictureBox1.Width, y)
Next
End Using
End Sub
If you want a different dot spacing, you could set the pen's DashStyle to Custom instead of to Dot as above:
Code:
pn.DashStyle = Drawing2D.DashStyle.Custom
pn.DashPattern = {1, 3}
That would give a 1 pixel dash (a dot) with 3 pixels of space.
BB
-
Dec 18th, 2013, 10:00 AM
#42
Addicted Member
-
Dec 18th, 2013, 06:17 PM
#43
Re: FastPix: Rapid Pixel Processing for Dummies and Dudes
Hi Stealthrt,
If your mask is always defined geometrically, like your circular mask in the example, it shouldn't be too difficult. In that case, you can draw the shape on the red background with Graphics.SmoothingMode=Antialias and then Graphics.FillElllipse, and GDI+ will give the shape an anti-aliased edge. Then you can copy the red component of the mask pixels to the transparency of the image pixels much as you are doing at present. This should work too for more complex shapes such as rounded rectangles and text, in fact anything you can define as a GraphicsPath.
Otherwise -- as far as I know -- things are likely to be rather more difficult, although there are various possibilities. If the mask image consists of a "blob" of unknown shape, it's possible to analyse the edge as a polygon using the Marching Squares Algorithm. I've been thinking of posting an example of that algorithm in VB.Net to this code bank, but it will have to wait. For a good explanation, see this link.
An alternative is to "feather" the edges of the image. That means nibbling away the edge pixels of the masked image with decreasing transparency: Paint.Net and many other drawing programs have tools for doing that. It should also be possible to do it in VB.Net, although it may not be quick. Another possibility would be to apply a blur (box blur for simplicity, Gaussian blur for better results) to the borders of the image against a transparent background; that would be more like true anti-aliasing.
It's an interesting problem which I would like to tackle but I won't have time until the New Year.
BB
-
Feb 11th, 2014, 01:04 PM
#44
New Member
Re: FastPix: Rapid Pixel Processing for Dummies and Dudes
Hi!
What if I wanted to do this with a window handle using hDC/hWnd? Must I take screenshots of the application and then compare them or is there a way to replace the bitmap with a window handle?
Thanks.
-
Feb 11th, 2014, 01:43 PM
#45
Re: FastPix: Rapid Pixel Processing for Dummies and Dudes
Hi KM,
The FastPix class works only with 32-bit bitmaps. If you want to get a snapshot of your own form, complete with controls, you could consider using the form's DrawToBitmap method; it has a few limitations but it's simple to code. If it's another application, then I guess there isn't much alternative to getting a screenshot.
BB
-
Apr 18th, 2014, 02:02 PM
#46
Re: FastPix: Rapid Pixel Processing for Dummies and Dudes
I don't know if this will be seen, but I was wondering whether the timing was done with Integer Overflow Checks on or off? This code seems like it would really benefit from having them off, which should be safe to do. That might get you a couple more x in speed (to explain that odd statement, I'm making a reference to the fact that you already have 100x, so this might add a few more x).
My usual boring signature: Nothing
-
Apr 20th, 2014, 04:35 AM
#47
Re: FastPix: Rapid Pixel Processing for Dummies and Dudes
-
Jun 18th, 2014, 06:20 PM
#48
Addicted Member
Re: FastPix: Rapid Pixel Processing for Dummies and Dudes
Originally Posted by boops boops
Hi Stealthrt,
If your mask is always defined geometrically, like your circular mask in the example, it shouldn't be too difficult. In that case, you can draw the shape on the red background with Graphics.SmoothingMode=Antialias and then Graphics.FillElllipse, and GDI+ will give the shape an anti-aliased edge. Then you can copy the red component of the mask pixels to the transparency of the image pixels much as you are doing at present. This should work too for more complex shapes such as rounded rectangles and text, in fact anything you can define as a GraphicsPath.
Otherwise -- as far as I know -- things are likely to be rather more difficult, although there are various possibilities. If the mask image consists of a "blob" of unknown shape, it's possible to analyse the edge as a polygon using the Marching Squares Algorithm. I've been thinking of posting an example of that algorithm in VB.Net to this code bank, but it will have to wait. For a good explanation, see this link.
An alternative is to "feather" the edges of the image. That means nibbling away the edge pixels of the masked image with decreasing transparency: Paint.Net and many other drawing programs have tools for doing that. It should also be possible to do it in VB.Net, although it may not be quick. Another possibility would be to apply a blur (box blur for simplicity, Gaussian blur for better results) to the borders of the image against a transparent background; that would be more like true anti-aliasing.
It's an interesting problem which I would like to tackle but I won't have time until the New Year.
BB
Were you able to check on this, boops boops?
Last edited by Stealthrt; Jun 18th, 2014 at 07:33 PM.
-
Feb 24th, 2017, 07:56 AM
#49
Re: FastPix: Rapid Pixel Processing for Dummies and Dudes
BB,
This is good stuff. Thanks for putting it out there.
I am curious about how this compares to drawing using DirectX. I have a charting class that I use DX with so I can show dozens of charts each with 1,000+ points simultaneously with a 1 second refresh. When I first built the class, it absolutely choked using GDI. DirectX was the only way I could draw what I needed fast enough.
As I I understand it, FastPix essentially lock the image in memory and allows you to manipulate the raw data rather than having to go through the framework methods. With DX, you essentially create an array of vectors and present them. Beyond that I have no clue how DX works, but I am curious if you have done any, or have an idea of how FastPix would compare against DX. I realize that DX is used more as a 3D model environment, but it can also be use very effectively in 2D space as well.
I'd love to hear your thoughts.
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Feb 25th, 2017, 05:25 AM
#50
Re: FastPix: Rapid Pixel Processing for Dummies and Dudes
I sometimes wonder why GetPixel and SetPixel weren't made more efficient in the first place. It's as though LockBits was added on to System.Drawing as an afterthought, as a slightly hacky extension for geeks only. LockBits and hence also FastPix utilize methods of the System.Drawing.Bitmap, so they are firmly rooted in GDI+. That's why they are closely associated with Windows.Forms, and seem relatively at home with VB.Net. But pixel-based processing with GDI+ relies on the CPU. Once you have decided what you want to paint, it doesn't paint pixels onto the screen any faster than GDI+ can achieve.
I don't have much experience with DirectX (or related packages such as XNA) but it's clearly capable of slapping pixels onto the screen much faster than GDI+ can. DirectX is also particularly good for things like animation, 3D drawings, transparency (and hence anti-aliasing) and colour gradients, because it can take full advantage of modern graphics hardware (GPU). It doesn't work well with individual pixels but I should think you could do highly efficient image processing in terms of triangle meshes and textures.
Interestingly, the .Net framework has a nicely packaged version of DirectX (in particular, the subset known as Direct3D) built into it. It doesn't involve downloading and installing special DLLs and it's accessible in Visual Studio just by selecting a suitable project template. It adapts to different graphics hardware capabilities and it has sound memory management. All its classes and interfaces are exhaustively documented in msdn complete with coding examples in Csharp and usually in VB.Net too. It's called WPF.
BB
-
Feb 15th, 2019, 06:33 AM
#51
Re: FastPix: Rapid Pixel Processing for Dummies and Dudes
Boops, have you ever thought about using GPU CUDA's to speed up FastPix?
I'm sure people would pay for that version!
-
Feb 15th, 2019, 06:34 AM
#52
Re: FastPix: Rapid Pixel Processing for Dummies and Dudes
Boops, have you ever thought about using GPU CUDA's to speed up FastPix?
I'm sure people would pay for that version!
-
Feb 21st, 2019, 06:37 AM
#53
Re: FastPix: Rapid Pixel Processing for Dummies and Dudes
Hi Peter,
sorry I didn't answer earlier, it seems like the forum has unsubscribed me from everything so I don't get notified. As to your question,
Originally Posted by Peter Porter
have you ever thought about using GPU CUDA's to speed up FastPix?
The answer is No.
Wikipedia explains that CUDA is a technology for use with suitably enabled NVIDIA GPU hardware, which is designed for programming in languages such as C++. Its main purpose is to provide efficient high-resolution 3D graphics. That's a long way from simple 2D image processing in VB.Net which could be the business of LockBits or FastPix. Maybe there are applications that benefit from combining them, but I suspect it would be bit like trying to pair an alloy bicycle wheel (FastPix) with a formula 1 engine (CUDA etc.); you'd have to think carefully about the drive train!
If I felt a need to combine pixel based image processing with fast 3D rendering, I would consider using a WriteableBitmap in WPF with its rendering based on Direct3D. And I expect there are other, better ways of exploiting GPU hardware.
BB
Last edited by boops boops; Feb 21st, 2019 at 06:42 AM.
-
Oct 21st, 2019, 09:18 AM
#54
Junior Member
Re: FastPix: Rapid Pixel Processing for Dummies and Dudes
Hi boops, sorry to resurrect such an old post but I am after a little help. I'm trying to use fastpix to make an "on the fly" green screen application, wherein the user selects a background from a selection of predefined images; then they take a photo that shows them on their chosen background in real time (like a photo booth) I did download Peter's project and saw that it worked flawlessly, but I didn't really understand the code to translate it into what I'm trying to achieve. Any help would be greatly appreciated
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|