Image Processing

I need some assistance with image processing.

I am attempting to merge two images into a single image for 3D viewing. Picture a stereoscope picture with a left and right image side-by-side. I have a large number of image pairs so I want to automate it.

I adapted one of the Xojo examples to do this successfully, but it is rather slow, mostly because (I assume) each image has to be drawn and displayed on the monitor. I just want to read in two images and save them as a concatenated image pair for 3D viewing. If I could do it without the slowdown of drawing to the screen, that would suffice.

Any suggestions? If you could point me to example code or a method that should work under Xojo, that would suffice.

Dim p as new picture( combinedWidth, height )
Dim g as graphics = p.graphics

Then do all your drawing into G

Save P

There are many reasons as to why it might feel slow; probably because it has to open and decode two large images, then write out an even larger image.

How are you displaying them?
Sam’s suggestion creates one LARGE image made up by pasting the two other images side by side and saving them… .but does nothing about displaying them.

using DrawPicture in the Paint event of a canvas should be very quick… assuming that you are not attempting to animate anything

g.drawpicture picLEFT,0,0,g.width/2,g.height , 0,0,picLeft.width,picLeft.height
g.drawpicture picRIGHT,g.width/2,0,g.width/2,g.height ,0,0,picRight.width,picRIght.height

obviously the values in the DrawPicture will need to be adjusted based on the aspect ratio of the screen and the aspect ratios of each picture

Thanks, guys, for the help.

Sam: I implemented your suggestion and noted an improvement of about 45% in execution time. Based on ten sample runs of before and after, using 360 image pairs.

Dave: I may implement this later if I decide to allow the user to view the images as they are being processed. This is an app for converting image pairs of a rotating object into a 3D video, so it probably wouldn’t be suitable for converting a slew of unrelated image pairs. For that, I might want to add background audio of Mason Williams’ “Classical Gas” to accompany it (that’s for those old enough to remember the Smother Brothers Show). :slight_smile:

Thanks a bunch!

Excellent, glad I could help. I honestly don’t think you’ll get it much faster as the bottleneck with doing what you’re doing is not Xojo. A lot of these kind of functions operate at an unperceptive differences to native OS functions.

I would recommend if you want to display the image to the user while your program is working, is to create a a pixel optimized image off-screen, then display it on screen. When I say pixel optimized, I mean a perfect pixel to pixel image so that no scaling has to be done when it’s displayed on screen, even today Apple recommends against using the OS to scale an image when displaying it on screen, if you want performance.

Which makes perfect sense, when you understand that on screen graphics are handled by the graphics card, images to be displayed have to uploaded from RAM to VRAM, so if you upload a large image (which takes longer) only for it to be displayed at a smaller size, you’re not only wasting time uploading wasted pixels, but you’re causing the GPU to have to resize the image, and then cache it at that size, then draw it. All of which can be avoided be you simply resizing the image before drawing it.

Thanks. Scaling is not in my plans.

Currently, I plan to put up one image to show user what’s being processed, then provide a progress bar. I’m not sure, under those conditions, a continual display of images being processed is necessary or desirable.