Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic picture cropping and resizing

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
0
0
AU
I have in mind making the following app that might be useful to many home video editors-

During our recent overseas, my wife just took over two thousand 3x4 12mpx pics and I videoed about 5 hours of HD video

I want to include many of these still pics in the final video but the only way to do it properly is to first crop any part of the 3x4 picture with a set ratio of 16x9 then reduce the resolution to exactly 1920x1080 pixels to match the video frames before inserting them into the video editing timeline.

This is a very laborious process to do to each frame in something like Photoshop that is designed to crop either to photo aspect ratios line 5x7 or 6x10 or a free form ratio.
Free form makes it impossible to preserve the 16x9 ratio.
Using a video editor gives quite inferior quality.

The photo cropping needs to be variable because often more of the bottom of the original 3x4 photo needs to be cropped off than the top but the ratio needs to be locked to 16x9 at all times.

Then the resulting JPG must be saved at a fixed resolution with the original file name with an extra letter or renamed eg. EmpireStateA.JPG

Any suggestions as to what to use to crop, resize and save a JPG would be greatly appreciated?
 
You can probably do most of what you need using the Wang Image Edit object (See for example I use it in an Excel app (of all things!) to do batch processing of images - mostly to be able to reduce their size down to something emailable.

I'm not certain about whether it will allow you to exactly resize to the precise size you want in the precise manner (e.g. crop, scale - whatever), but it will certainly let you do cropping and re-scaling. It will also save as jpg.

If you need more explicit control of scaling and cropping, see GetBitMapBits() and SetBitMapBits(). The former allows you to grab the pixel data of an image displayed on a picturebox or form and (after you have frigged with the data array in whatever way you want to scale / crop appropriately) the latter allows you to re-display it as an picture. The Wang tool can then be used to save as a jpg.

I don't think it shipped with XP, but if you upgraded your current system from 2000 or earlier, or have an old machine knocking around, you should be able to find it. If not, you should be able to find it available for download.

It is also worth browsing back through previous posts from strongm on related subjects, e.g GDI32.

Any use to you?

Tony
 
Ted:

I'm a little confused. Resolution is DPI (dots per inch) not pixel size. Pixel size is determined by Inches X DPI. For example, a 3x4 inch image with a DPI of 300 is 900x1200 pixels.

An image set to 1920x1080 pixels at 300 DPI would be 6.40x3.60 inches. The same image, 1920x1080 pixels at 96 DPI (standard PC Monitor resolution) would be 20x11.25 inches.

So the questions I have are:

1. What is the DPI of the 3x4 images you're working with?
2. What is the DPI desired for the end result video frames?

 
>So the questions I have are:
>
> 1. What is the DPI of the 3x4 images you're working with?
> 2. What is the DPI desired for the end result video frames?

DPI is not the issue here. Ted is looking to produce a 1080p HD image.

>Wang Image Edit

Actually, I'd be tempted to do this with Microsoft's Window Image Aquisition library. You could write (and I've just knocked a test together to check this) a cropper/resizer/jpg saver in about 10 lines of code. I'll leave Ted to write his own version.

 
Thanks for the suggestions.
On second thoughts I have found the other tools in Photoshop such as sharpen and color correction very useful so I am now considering some sort of automation of photoshop instead.

I might be able to get away with sendkeys statements to create a sort of macro for Photoshop. I guess sharpening and color correction is beyond Vb6.(unless someone has a better way of doing this?)

The major problem with Photoshop seems to be I can't keep a fixed ratio of 16x9 when I am adjusting cropping as it's fixed option only caters for photo sizes like 5x7 or 6x8. The only other option is variable and this is impossible to keep a constant ratio.
Eg you may want to reduce the width slightly then you have to use a hand calculator to get a value 9/16 of the height and enter it in the width box.
When satisfied with the cropping you enter 1920 in width and 1080 in height and it automatically sets the correct "resolution" without disturbing the visual cropping.
Maybe I could automate this laborious process in VB6?

Regarding "Resolution". This is not related to dots per inch otherwise that would mean that the same photograph would have a lower resolution if you simply enlarged it to a larger sheet of paper.

Resolution of a picture is the number of black AND white dots you can display in any given picture width or height regardless of the size of picture.
Dots per inch of a picture obviously changes for the same picture enlarged to different paper sizes but niot the resolution of the original picture.
Dots per inch of a printer setting doesn't change with paper sizes as it refers to the number of printer dots that are usually quite different to the pixels of the picture.
Both have to be taken into account when defining the resolution of a final paper photograph

Eg for a 1920x1080 pixel monitor the maximum horizontal resolution of the original picture is 910 and the vertical resolution is 540 (half the number of pixels)

Commonly these days the 'number of pixels' is used for resolution because it sounds better on the sales blurb (being twice the value)

In old CRT screens horizontal resolution was limited by the bandwidth of the video amplifer and video source quality, vertical resolution was limited by the number of lines used (one half of 535 in the case of NTSC unless the camera was out of focus as well)
The number of pixels of colored dots on a CRT was usually THREE TIMES the resolution so the independent dots were never visible at normal viewing distance. This was because it was impossible to exactly line up the colored dots with each electron beam so they would spray over a number of dots in the hope of hitting a few using a mask with holes in it in between.

With the introduction of LCDs and digital video the pixel can be exactly matched up with the video bits and bytes

Using any video other than what exactly matches the native pixels of the LCD TV used, always gives an inferior result which is why I want the app I describe.
 
>I guess sharpening and color correction is beyond Vb6

You can do it in VB6. Sharpening isn't particularly straightforward, but color correction (depending on what you want) can be. In both cases I'd be looking at using GDI+, which I've previously pointed out to you. But if, as you say, you have Photoshop then you'll get better control, effects and results in that (writing good convolution filters is not a 5 minute job).

>Eg for a 1920x1080 pixel monitor the maximum horizontal resolution of the original picture is 910 and the vertical resolution is 540 (half the number of pixels)

Not on my monitor
 
Sorry I meant, A 1920 wide monitor has 960 horizontal resolution

This is the maximum number of white dots on black that can be displayed at a time which is the definition of resolution. If you had them all on across the screen you would have a white line.

Thanks for the advice on InfanView. I'll try it.
 
>I guess sharpening and color correction is beyond Vb6

As strongm suggests sharpening can be a tab complicated, but de-smearing and de-blurring can be done. It helps if you know what the blur-function or smear-function was. However, it can be done without prior knowledge using a blind-deconvolution process. See, for example, the Lucy-Richardson algorithm.

strongm - does GDI+ have any inbuilt blind-deconvolution capabilities? Or any other forms of Fourier processing?

Tony
 
>does GDI+ have any inbuilt blind-deconvolution capabilities? Or any other forms of Fourier processing?

Sadly not.
 
Ted, I use Sony Vegas Pro, a professional NLE video editor which will do resizing, sharpening, colour correction and a million other things with just a few mouse clicks. You can dump your 2000 photo's onto the timeline in one action then just set the output resolution, aspect ratio etc to match your HD Video project properties. You can even preset the viewing length of each image to whatever duration you require and all 2000 will play back at that duration.

The current version of Sony Vegas is 11. I use 10 but any of the previous versions from 7 will do what you're trying to achieve in HD. They also do a 'poor man's' version called Vegas Movie Studio.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
I have been using Adobe Premier Elements 9 to do the editing, using only Full HD.

It does the same as Sony Vegas Movie Studio.

I can't afford the professional versions of either!

While there is no problem with standard DVDs, you never get quite the same picture quality with a cheap movie editor when you use it to reduce and crop a 3000x4000 pixel still to a 1920x1080 HD movie interlaced frame.

Also if you have many such frame reductions in a movie (as I have)then processing needed is huge when you try to preview or render it with say a dissolve or transition as well between the still and a movie.
If you make it exactly the same spec as the movie you don't even have to render it and you can have as many as you like.

Any attempt to resize and convert a frame, even slightly, always reduces the final resolution in some way unless you do it in exact multiples. Photoshop seems to be the best quality "converter" around and they have been doing it for a long time.

Pre-converting them like I do is the poor man's way of achieving the same quality and editing speed you get with professional editors. That is why I wanted an easier to use "converter".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top