-
May 14th, 2012, 04:37 PM
#1
Quick Array Copy
Hi,
What would be a quick way to transfer the contents from an array of int[,] to UInt16[]?
I am loading up the UInt16[] array for use in a BitmapSource object. The BitmapSource object is then associated with a WPF control image.Source to render it.
Ideas appreciated. It is currently taking an extremely long time.
Thanks,
Alan
-
May 15th, 2012, 01:02 AM
#2
Re: Quick Array Copy
Define "extremely long": 1 month, 1 week, 1 hour, 1 minute, ...?
What is the size of array?
How did you implement this copying?
Victor Nijegorodov
-
May 15th, 2012, 04:20 AM
#3
Re: Quick Array Copy
Before we can give suggestions to speed it up, we need to know how you are currently doing it
But do you even need to do a copy in the first place? Could you just use a UInt16 array instead of the original int array?
And does this need to be fully portable, or is machine-specific code (including assembler) allowed?
-
May 17th, 2012, 09:28 AM
#4
Re: Quick Array Copy
Also looks like a .net array of some type, or maybe C#???
What compiler / tools are you using? Also what programming language (/ extensions etc)?
ahoodin
To keep the plot moving, that's why.
-
May 17th, 2012, 11:34 AM
#5
Re: Quick Array Copy
Thanks for the replies. This is in C# so slightly preferred in that language/.NET, but open to anything that works. The copy is doing it pixel value by pixel value for a camera and is taking over 90 seconds. It would be great to get the copy/convert down to 2 seconds or less if possible (or somehow use the original array in the created bitmap). The total size is 8 megapixels. I am getting the source/original int[,] array data from the camera driver. The UInt16 is needed (or so I think) to create the bitmap used for display in the image control. It would be great if I could find a way to use the int[,] array directly without having to convert/copy it to the UInt16 array. The prototype code looks like:
//Source
int[,] imgArray = (int[,])C.ImageArray;
//Destination
UInt16[] img2Array = new UInt16[DestinationArraySize];
//Loop that transfers "int" camera data in 2d array (from camera) to "UInt16" array. UInt16 array is needed for the bitmap used by the image control for display.
//Loop (most details of loop not shown)
...
//Core line in loop that copies/converts 1 camera value from the int[,] array to the UInt16[] array.
img2Array[i] = (UInt16)(imgArray[iYPosition, iXPosition]
...
//Destination array is put into the bitmap
BitmapSource bitmap = BitmapSource.Create(width, height,
96, 96, pf, null,
img2Array, rawStride);
//Newly created bitmap with destination array is associated with the image control for display
image1.Source = bitmap;
Thanks Again!
Alan
-
May 17th, 2012, 11:43 AM
#6
Re: Quick Array Copy
I suspect that the problem lies here:
Code:
//Loop (most details of loop not shown)
...
The 'copy' part of the code shouldn't be taking anything close to 90 seconds for an 8 megapixel image. So what happens in the rest of the loop?
-
May 17th, 2012, 12:21 PM
#7
Re: Quick Array Copy
Maybe you could implement only this part in a C DLL. It will probably be faster than anything you can achieve with .NET. You could also make use of SSE.
By the way, I'm wondering why do you have to convert from int to Uint16?
-
May 17th, 2012, 03:47 PM
#8
Re: Quick Array Copy
UInt16 is used since I know it works in the Bitmapsource derived object for display within an image control (WPF). The very prototype code is as follows. This is very rough just wanted to get something that would convert the data from one source array to the destination. The 90+ seconds is in debug mode.
int i = 0;
int ImageSize= CameraXSize * CameraYSize;
while (i < ImageSize)
{
iXPosition = 0;
//Go across row doing copy/conversion
while (iXPosition < CameraXSize)
{
img2Array[i] = (UInt16)(imgArray[iYPosition, iXPosition]);//Note: x and y position appear reversed for preloaded array from driver
i++;
iXPosition++;
}
//Increment row
iYPosition++;
}
Thanks!!!
Alan
-
May 17th, 2012, 04:15 PM
#9
Re: Quick Array Copy
You say it takes 90 seconds in debug mode - but code performance in debug mode is not important. How long does it take in release mode?
-
May 21st, 2012, 12:01 PM
#10
Re: Quick Array Copy
It turns out much greater than 90 seconds. 4 minutes, 7 seconds in release non-debug mode. The array size is 2016x3040. Thanks! - Alan
-
May 21st, 2012, 01:29 PM
#11
Re: Quick Array Copy
Wow this sounds like real slow performance times. You may want to look at using some multi-threaded approaches. Computers take advantage of multiple cores and a multi-threaded approach is key here. In any case, sometimes at the very least decreasing image resolution may not degrade user experience significantly in every case.
ahoodin
To keep the plot moving, that's why.
-
November 26th, 2012, 03:51 AM
#12
Re: Quick Array Copy
Victor Nijegorodov
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
|