5 Update/refresh
source | link

SMALL UPDATE: This question is left as unanswered, because none of the existing answers as of yet actually use CUDA (though, whilst being very useful).

2nd Edition: To make it a bit more clear, and to summarize the discussion in comments.

I have a small image, like this one:

InsertImage = 
 DensityPlot[Sqrt[1 - x^2 - y^2], {x, -1, 1}, {y, -1, 1}, 
  Frame -> False, 
  ColorFunction -> (Opacity[Max[Re[#], 0], 
      GrayLevel[Max[Re[#], 0]]] &), ImageSize -> 40, 
  Background -> Opacity[0, Black]]

It is just a semi-transparent gray ball: enter image description here Outside the ball you see white - because of transparency.

I have a big background, like this one:

InsertIntoImage = Image[GrayLevel[0], ImageSize -> 400];

It is just big black background.

I want to insert the small image into the big one many-many times, e.g. at these scaled positions:

PosList = {Cos[Pi #], Sin[4 Pi #]}^2 & /@ Range[0, 1, 0.005];

Vaguely, the result should be like:

Rasterize[
  Graphics[{Inset[InsertIntoImage], 
    Inset[InsertImage, Scaled[#]] & /@ PosList}, 
   ImageSize -> 400]] // AbsoluteTiming

enter image description here

Ideally:

  1. I want to add up only grayscale channels of big and small images.
  2. Small images are to be added really many times - it is for video production, and the above example is a very light version of it.
  3. I want to make it work fast for many more images at a time: Inset is way too slow.

Question: How to do it with CUDA?

Notes on CUDA (why CUDA):

  1. It should work much faster. Note, the overhead of caching one small image is negligible.

  2. I can't seem to find an appropriate inbuilt function: CUDAImageAss[] uses only images of similar size.

  3. Putting small images pixel by pixel in matrix form is not very much to my liking. I want to be able to specify small image positions at subpixel accuracy. Normally, this would smear each pixel of each small image with a pointspread function. It is doable, but I believe there must be existing algorithms.

  4. Such a problem must have been solved a thousand times, e.g. in videogames, movie production, etc. Note, that GPUs in videogames allow rendering in realtime, hence this approach should work fast here too.

2nd Edition: To make it a bit more clear, and to summarize the discussion in comments.

I have a small image, like this one:

InsertImage = 
 DensityPlot[Sqrt[1 - x^2 - y^2], {x, -1, 1}, {y, -1, 1}, 
  Frame -> False, 
  ColorFunction -> (Opacity[Max[Re[#], 0], 
      GrayLevel[Max[Re[#], 0]]] &), ImageSize -> 40, 
  Background -> Opacity[0, Black]]

It is just a semi-transparent gray ball: enter image description here Outside the ball you see white - because of transparency.

I have a big background, like this one:

InsertIntoImage = Image[GrayLevel[0], ImageSize -> 400];

It is just big black background.

I want to insert the small image into the big one many-many times, e.g. at these scaled positions:

PosList = {Cos[Pi #], Sin[4 Pi #]}^2 & /@ Range[0, 1, 0.005];

Vaguely, the result should be like:

Rasterize[
  Graphics[{Inset[InsertIntoImage], 
    Inset[InsertImage, Scaled[#]] & /@ PosList}, 
   ImageSize -> 400]] // AbsoluteTiming

enter image description here

Ideally:

  1. I want to add up only grayscale channels of big and small images.
  2. Small images are to be added really many times - it is for video production, and the above example is a very light version of it.
  3. I want to make it work fast for many more images at a time: Inset is way too slow.

Question: How to do it with CUDA?

Notes on CUDA (why CUDA):

  1. It should work much faster. Note, the overhead of caching one small image is negligible.

  2. I can't seem to find an appropriate inbuilt function: CUDAImageAss[] uses only images of similar size.

  3. Putting small images pixel by pixel in matrix form is not very much to my liking. I want to be able to specify small image positions at subpixel accuracy. Normally, this would smear each pixel of each small image with a pointspread function. It is doable, but I believe there must be existing algorithms.

  4. Such a problem must have been solved a thousand times, e.g. in videogames, movie production, etc. Note, that GPUs in videogames allow rendering in realtime, hence this approach should work fast here too.

SMALL UPDATE: This question is left as unanswered, because none of the existing answers as of yet actually use CUDA (though, whilst being very useful).

2nd Edition: To make it a bit more clear, and to summarize the discussion in comments.

I have a small image, like this one:

InsertImage = 
 DensityPlot[Sqrt[1 - x^2 - y^2], {x, -1, 1}, {y, -1, 1}, 
  Frame -> False, 
  ColorFunction -> (Opacity[Max[Re[#], 0], 
      GrayLevel[Max[Re[#], 0]]] &), ImageSize -> 40, 
  Background -> Opacity[0, Black]]

It is just a semi-transparent gray ball: enter image description here Outside the ball you see white - because of transparency.

I have a big background, like this one:

InsertIntoImage = Image[GrayLevel[0], ImageSize -> 400];

It is just big black background.

I want to insert the small image into the big one many-many times, e.g. at these scaled positions:

PosList = {Cos[Pi #], Sin[4 Pi #]}^2 & /@ Range[0, 1, 0.005];

Vaguely, the result should be like:

Rasterize[
  Graphics[{Inset[InsertIntoImage], 
    Inset[InsertImage, Scaled[#]] & /@ PosList}, 
   ImageSize -> 400]] // AbsoluteTiming

enter image description here

Ideally:

  1. I want to add up only grayscale channels of big and small images.
  2. Small images are to be added really many times - it is for video production, and the above example is a very light version of it.
  3. I want to make it work fast for many more images at a time: Inset is way too slow.

Question: How to do it with CUDA?

Notes on CUDA (why CUDA):

  1. It should work much faster. Note, the overhead of caching one small image is negligible.

  2. I can't seem to find an appropriate inbuilt function: CUDAImageAss[] uses only images of similar size.

  3. Putting small images pixel by pixel in matrix form is not very much to my liking. I want to be able to specify small image positions at subpixel accuracy. Normally, this would smear each pixel of each small image with a pointspread function. It is doable, but I believe there must be existing algorithms.

  4. Such a problem must have been solved a thousand times, e.g. in videogames, movie production, etc. Note, that GPUs in videogames allow rendering in realtime, hence this approach should work fast here too.

4 converted quote blocks to code blocks
source | link

2nd Edition: To make it a bit more clear, and to summarize the discussion in comments.

I have a small image, like this one:

InsertImage = DensityPlot[Sqrt[1 - x^2 - y^2], {x, -1, 1}, {y, -1, 1}, Frame -> False, ColorFunction -> (Opacity[Max[Re[#], 0], GrayLevel[Max[Re[#], 0]]] &), ImageSize -> 40, Background -> Opacity[0, Black]]

InsertImage = 
 DensityPlot[Sqrt[1 - x^2 - y^2], {x, -1, 1}, {y, -1, 1}, 
  Frame -> False, 
  ColorFunction -> (Opacity[Max[Re[#], 0], 
      GrayLevel[Max[Re[#], 0]]] &), ImageSize -> 40, 
  Background -> Opacity[0, Black]]

It is just a semi-transparent gray ball: enter image description here Outside the ball you see white - because of transparency.

I have a big background, like this one:

InsertIntoImage = Image[GrayLevel[0], ImageSize -> 400];

InsertIntoImage = Image[GrayLevel[0], ImageSize -> 400];

It is just big black background.

I want to insert the small image into the big one many-many times, e.g. at these scaled positions:

PosList = {Cos[Pi #], Sin[4 Pi #]}^2 & /@ Range[0, 1, 0.005];

PosList = {Cos[Pi #], Sin[4 Pi #]}^2 & /@ Range[0, 1, 0.005];

Vaguely, the result should be like:

Rasterize[ Graphics[{Inset[InsertIntoImage], Inset[InsertImage, Scaled[#]] & /@ PosList}, ImageSize -> 400]] // AbsoluteTiming

Rasterize[
  Graphics[{Inset[InsertIntoImage], 
    Inset[InsertImage, Scaled[#]] & /@ PosList}, 
   ImageSize -> 400]] // AbsoluteTiming

enter image description here

Ideally:

  1. I want to add up only grayscale channels of big and small images.
  2. Small images are to be added really many times - it is for video production, and the above example is a very light version of it.
  3. I want to make it work fast for many more images at a time: Inset is way too slow.

Question: How to do it with CUDA?

Notes on CUDA (why CUDA):

  1. It should work much faster. Note, the overhead of caching one small image is negligible.

  2. I can't seem to find an appropriate inbuilt function: CUDAImageAss[] uses only images of similar size.

  3. Putting small images pixel by pixel in matrix form is not very much to my liking. I want to be able to specify small image positions at subpixel accuracy. Normally, this would smear each pixel of each small image with a pointspread function. It is doable, but I believe there must be existing algorithms.

  4. Such a problem must have been solved a thousand times, e.g. in videogames, movie production, etc. Note, that GPUs in videogames allow rendering in realtime, hence this approach should work fast here too.

2nd Edition: To make it a bit more clear, and to summarize the discussion in comments.

I have a small image, like this one:

InsertImage = DensityPlot[Sqrt[1 - x^2 - y^2], {x, -1, 1}, {y, -1, 1}, Frame -> False, ColorFunction -> (Opacity[Max[Re[#], 0], GrayLevel[Max[Re[#], 0]]] &), ImageSize -> 40, Background -> Opacity[0, Black]]

It is just a semi-transparent gray ball: enter image description here Outside the ball you see white - because of transparency.

I have a big background, like this one:

InsertIntoImage = Image[GrayLevel[0], ImageSize -> 400];

It is just big black background.

I want to insert the small image into the big one many-many times, e.g. at these scaled positions:

PosList = {Cos[Pi #], Sin[4 Pi #]}^2 & /@ Range[0, 1, 0.005];

Vaguely, the result should be like:

Rasterize[ Graphics[{Inset[InsertIntoImage], Inset[InsertImage, Scaled[#]] & /@ PosList}, ImageSize -> 400]] // AbsoluteTiming

enter image description here

Ideally:

  1. I want to add up only grayscale channels of big and small images.
  2. Small images are to be added really many times - it is for video production, and the above example is a very light version of it.
  3. I want to make it work fast for many more images at a time: Inset is way too slow.

Question: How to do it with CUDA?

Notes on CUDA (why CUDA):

  1. It should work much faster. Note, the overhead of caching one small image is negligible.

  2. I can't seem to find an appropriate inbuilt function: CUDAImageAss[] uses only images of similar size.

  3. Putting small images pixel by pixel in matrix form is not very much to my liking. I want to be able to specify small image positions at subpixel accuracy. Normally, this would smear each pixel of each small image with a pointspread function. It is doable, but I believe there must be existing algorithms.

  4. Such a problem must have been solved a thousand times, e.g. in videogames, movie production, etc. Note, that GPUs in videogames allow rendering in realtime, hence this approach should work fast here too.

2nd Edition: To make it a bit more clear, and to summarize the discussion in comments.

I have a small image, like this one:

InsertImage = 
 DensityPlot[Sqrt[1 - x^2 - y^2], {x, -1, 1}, {y, -1, 1}, 
  Frame -> False, 
  ColorFunction -> (Opacity[Max[Re[#], 0], 
      GrayLevel[Max[Re[#], 0]]] &), ImageSize -> 40, 
  Background -> Opacity[0, Black]]

It is just a semi-transparent gray ball: enter image description here Outside the ball you see white - because of transparency.

I have a big background, like this one:

InsertIntoImage = Image[GrayLevel[0], ImageSize -> 400];

It is just big black background.

I want to insert the small image into the big one many-many times, e.g. at these scaled positions:

PosList = {Cos[Pi #], Sin[4 Pi #]}^2 & /@ Range[0, 1, 0.005];

Vaguely, the result should be like:

Rasterize[
  Graphics[{Inset[InsertIntoImage], 
    Inset[InsertImage, Scaled[#]] & /@ PosList}, 
   ImageSize -> 400]] // AbsoluteTiming

enter image description here

Ideally:

  1. I want to add up only grayscale channels of big and small images.
  2. Small images are to be added really many times - it is for video production, and the above example is a very light version of it.
  3. I want to make it work fast for many more images at a time: Inset is way too slow.

Question: How to do it with CUDA?

Notes on CUDA (why CUDA):

  1. It should work much faster. Note, the overhead of caching one small image is negligible.

  2. I can't seem to find an appropriate inbuilt function: CUDAImageAss[] uses only images of similar size.

  3. Putting small images pixel by pixel in matrix form is not very much to my liking. I want to be able to specify small image positions at subpixel accuracy. Normally, this would smear each pixel of each small image with a pointspread function. It is doable, but I believe there must be existing algorithms.

  4. Such a problem must have been solved a thousand times, e.g. in videogames, movie production, etc. Note, that GPUs in videogames allow rendering in realtime, hence this approach should work fast here too.

3 Clarification
source | link

CUDAImageAdd for Combining images of different sizewith CUDA

Preamble2nd Edition: I am quite new to CUDA programming To make it a bit more clear, and yetto summarize the following problem seems not very trivialdiscussion in comments.

GoalI have a small image: I want to efficiently put many small sized images (say, 10x10 pixels) onlike this one:

InsertImage = DensityPlot[Sqrt[1 - x^2 - y^2], {x, -1, 1}, {y, -1, 1}, Frame -> False, ColorFunction -> (Opacity[Max[Re[#], 0], GrayLevel[Max[Re[#], 0]]] &), ImageSize -> 40, Background -> Opacity[0, Black]]

It is just a larger imagesemi-transparent gray ball: enter image description here Outside the ball you see white (say, 1000x1000 pixels)- because of transparency.

A few thoughtsI have a big background: The most appropriate function I have found so far for, like this one:

InsertIntoImage = Image[GrayLevel[0], ImageSize -> 400];

It is Inset[]just big black background. However, it works slow when the number of small images gets too large

I want to insert the small image into the big one many-many times, e.g. 10000.at these scaled positions:

PosList = {Cos[Pi #], Sin[4 Pi #]}^2 & /@ Range[0, 1, 0.005];

GPU seems like a very promising approach to do such an image addition efficiently. Moreover, I believe this has been solved more than often in video games. However, the only CUDA function combining the imagesVaguely, CUDAImageAdd[] needs the images of same size. Whereas, if I set to write a customary CUDA-code, I would have to start from low-level image representation, which seemsresult should be like a long way to go.:

Rasterize[ Graphics[{Inset[InsertIntoImage], Inset[InsertImage, Scaled[#]] & /@ PosList}, ImageSize -> 400]] // AbsoluteTiming

enter image description here

QuestionIdeally: Are there standard CUDA functions, which: 1) Can add images of different size, 2) Can be integrated in Mathematica ?

  1. I want to add up only grayscale channels of big and small images.
  2. Small images are to be added really many times - it is for video production, and the above example is a very light version of it.
  3. I want to make it work fast for many more images at a time: Inset is way too slow.

Edit1, ClarifiationQuestion: How to do it with CUDA?

1) Among the small images only a small fraction is unique. Therefore the pre-caching overhead can be neglected.

2) Direct pixel-to-pixel operations on matrix level, e.g. putting a small image of size (0,0):(10,10) at pixels (600,600):(610,610) doesn't look as good as Inset[] or Graphics[] positioning. Probably, because of the imprecise positioning and lack of antialiasing.

Many thanks!Notes on CUDA (why CUDA):

  1. It should work much faster. Note, the overhead of caching one small image is negligible.

  2. I can't seem to find an appropriate inbuilt function: CUDAImageAss[] uses only images of similar size.

  3. Putting small images pixel by pixel in matrix form is not very much to my liking. I want to be able to specify small image positions at subpixel accuracy. Normally, this would smear each pixel of each small image with a pointspread function. It is doable, but I believe there must be existing algorithms.

  4. Such a problem must have been solved a thousand times, e.g. in videogames, movie production, etc. Note, that GPUs in videogames allow rendering in realtime, hence this approach should work fast here too.

CUDAImageAdd for images of different size

Preamble: I am quite new to CUDA programming, and yet the following problem seems not very trivial.

Goal: I want to efficiently put many small sized images (say, 10x10 pixels) on a larger image (say, 1000x1000 pixels).

A few thoughts: The most appropriate function I have found so far for this is Inset[]. However, it works slow when the number of small images gets too large, e.g. 10000.

GPU seems like a very promising approach to do such an image addition efficiently. Moreover, I believe this has been solved more than often in video games. However, the only CUDA function combining the images, CUDAImageAdd[] needs the images of same size. Whereas, if I set to write a customary CUDA-code, I would have to start from low-level image representation, which seems like a long way to go.

Question: Are there standard CUDA functions, which: 1) Can add images of different size, 2) Can be integrated in Mathematica ?

Edit1, Clarifiation:

1) Among the small images only a small fraction is unique. Therefore the pre-caching overhead can be neglected.

2) Direct pixel-to-pixel operations on matrix level, e.g. putting a small image of size (0,0):(10,10) at pixels (600,600):(610,610) doesn't look as good as Inset[] or Graphics[] positioning. Probably, because of the imprecise positioning and lack of antialiasing.

Many thanks!

Combining images with CUDA

2nd Edition: To make it a bit more clear, and to summarize the discussion in comments.

I have a small image, like this one:

InsertImage = DensityPlot[Sqrt[1 - x^2 - y^2], {x, -1, 1}, {y, -1, 1}, Frame -> False, ColorFunction -> (Opacity[Max[Re[#], 0], GrayLevel[Max[Re[#], 0]]] &), ImageSize -> 40, Background -> Opacity[0, Black]]

It is just a semi-transparent gray ball: enter image description here Outside the ball you see white - because of transparency.

I have a big background, like this one:

InsertIntoImage = Image[GrayLevel[0], ImageSize -> 400];

It is just big black background.

I want to insert the small image into the big one many-many times, e.g. at these scaled positions:

PosList = {Cos[Pi #], Sin[4 Pi #]}^2 & /@ Range[0, 1, 0.005];

Vaguely, the result should be like:

Rasterize[ Graphics[{Inset[InsertIntoImage], Inset[InsertImage, Scaled[#]] & /@ PosList}, ImageSize -> 400]] // AbsoluteTiming

enter image description here

Ideally:

  1. I want to add up only grayscale channels of big and small images.
  2. Small images are to be added really many times - it is for video production, and the above example is a very light version of it.
  3. I want to make it work fast for many more images at a time: Inset is way too slow.

Question: How to do it with CUDA?

Notes on CUDA (why CUDA):

  1. It should work much faster. Note, the overhead of caching one small image is negligible.

  2. I can't seem to find an appropriate inbuilt function: CUDAImageAss[] uses only images of similar size.

  3. Putting small images pixel by pixel in matrix form is not very much to my liking. I want to be able to specify small image positions at subpixel accuracy. Normally, this would smear each pixel of each small image with a pointspread function. It is doable, but I believe there must be existing algorithms.

  4. Such a problem must have been solved a thousand times, e.g. in videogames, movie production, etc. Note, that GPUs in videogames allow rendering in realtime, hence this approach should work fast here too.

2 added 410 characters in body
source | link
    Tweeted twitter.com/#!/StackMma/status/497098005263441921
1
source | link