473,385 Members | 1,673 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,385 software developers and data experts.

Can someone help me duplicate the effect now that I achieved speed ?

Look guys i'm at a total loss. My effect is nice and it runs fast but the effect does not match the one i'm trying to duplicate wondering if anyone can help me.


That is the effect i'm trying to create. This is my effect currently


Am I even on the right path ?
Here is the finalized code.
Expand|Select|Wrap|Line Numbers
  1.  Private Function EdgeDetect(bmp As Bitmap) As Bitmap
  2.         'convert any input bitmap into jpg just to make sure to have the correct byte order
  3.         If Not bmp.RawFormat.Equals(ImageFormat.Jpeg) Then
  4.             Using msJPG As New IO.MemoryStream()
  5.                 bmp.Save(msJPG, ImageFormat.Jpeg)
  6.                 bmp = CType(Image.FromStream(msJPG), Bitmap)
  7.             End Using
  8.         End If
  9.         'setting up the lockbits
  10.         Dim raz As Integer = bmp.Height \ 3
  11.         Dim height As Integer = bmp.Height
  12.         Dim width As Integer = bmp.Width
  13.         Dim rect As New Rectangle(Point.Empty, bmp.Size)
  14.         Dim bmpData As BitmapData = bmp.LockBits(rect, ImageLockMode.ReadWrite, bmp.PixelFormat)
  15.         Dim bpp As Integer = If((bmp.PixelFormat = PixelFormat.Format32bppArgb), 2, 3)
  16.         Dim size As Integer = bmpData.Stride * bmpData.Height
  17.         Dim data As Byte() = New Byte(size - 1) {}
  18.         Dim result As Byte() = New Byte(size - 1) {}
  19.         Marshal.Copy(bmpData.Scan0, data, 0, size)
  20.         Marshal.Copy(bmpData.Scan0, result, 0, size) 'duplicate so that edge finding can run in parallel without using pixels as samples that have already been processed themselves
  21.         'edge detection
  22.         Dim stride As Integer = bmpData.Stride
  23.         'convert to grayscale first, makes finding edges cheaper later
  24.         Parallel.For(0, width, Sub(totallynewX)
  25.                                    Dim totallynewi As Integer
  26.                                    For totallynewY As Integer = 0 To height - 1
  27.                                        totallynewi = totallynewY * stride + totallynewX * bpp
  28.                                        Dim avg As Byte = CByte(Math.Min(data(totallynewi) * 0.299 + data(totallynewi + 1) * 0.587 + data(totallynewi + 2) * 0.114, 255)) 'formula for accurate grayscale
  29.                                        result(totallynewi) = avg
  30.                                        result(totallynewi + 1) = avg
  31.                                        result(totallynewi + 2) = avg
  32.                                    Next
  33.                                End Sub)
  34.  
  35.         'now find edges
  36.         Parallel.For(0, height, Sub(horizontal)
  37.                                     Dim pixel1, pixel2 As Integer
  38.                                     Dim total, index As Integer
  39.                                     For vertical As Integer = 0 To width - 1
  40.                                         Dim offset As Integer = 1
  41.                                         If horizontal = height - 1 OrElse vertical = width - 1 Then offset = 0
  42.                                         index = horizontal * stride + vertical * bpp
  43.                                         pixel1 = data(index)
  44.                                         index = (horizontal + offset) * stride + (vertical + offset) * bpp
  45.                                         pixel2 = data(index)
  46.                                         total = Math.Min(Math.Abs(pixel1 - pixel2) + 128, 255)
  47.                                         index = horizontal * stride + vertical * bpp
  48.                                         result(index) = CByte(total)
  49.                                         result(index + 1) = CByte(total)
  50.                                         result(index + 2) = CByte(total)
  51.                                     Next
  52.                                 End Sub)
  53.  
  54.         Marshal.Copy(result, 0, bmpData.Scan0, data.Length)
  55.         bmp.UnlockBits(bmpData)
  56.         Return bmp
  57.     End Function
This provides me with the second image effect.
Feb 5 '16 #1
0 1115

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Fred Bennett | last post by:
I have a simulation project in which data can naturally be held in structures for processing. There are calls to multiple functions involved. Execution speed is an issue. Do I take a big hit for...
1
by: Mike | last post by:
Hello, I can't find any javascript that reads and writes cookies with keys, so that it is compatible with ASP (I want to read and write cookies from both javascript and ASP) for example in...
0
by: Bill | last post by:
I have a db that tracks students and classes. On my main form I have student info. I then have a button on the main form that pops up another form that allows someone to add that student to a...
9
by: Jerry | last post by:
Can someone explain the underlying implications of this statement: "#define P printf" ? I've been told that printf is called off of the heap instead of the stacks, so P calls are much faster than...
16
by: raj | last post by:
Hi, I saw it mentioned that "int" is the fastest data-type for use in C ,that is data storage/retrieval would be the fastest if I use int among the following 4 situations in a 32 bit machine with...
5
by: Russell Warren | last post by:
Does anyone have an easier/faster/better way of popping from the middle of a deque than this? class mydeque(deque): def popmiddle(self, pos): self.rotate(-pos) ret = self.popleft()...
7
by: ucfcpegirl06 | last post by:
Hello, I have a dilemma. I am trying to flag duplicate messages received off of a com port. I have a software tool that is supposed to detect dup messages and flag and write the text "DUP" on...
9
by: Russell Mangel | last post by:
Can someone show me how to speed this up? 1. Whats the fastest way for Unsafe C#? 2. What the fastest way for Safe C#? public static Int64 ToInt64(Int32 low, Int32 high) { Byte lowBytes =...
4
by: binchaud | last post by:
Is there a way to create a dynamic mirror effect that will create a reflection regardless of what is placed above a set line? Meaning, we should not have to duplicate symbols, flip them and...
1
by: Jason7899 | last post by:
hi, i have seen some sites the have the photos with the effect that vista and mac does with the icons of the programs that is running, i have seen other cool effect that is the picture of the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.