How to re-size .bmp file in C\C++? - c++

I am doing a CBIR system as an assignment.There are 100 .bmp files,but they have different size,how to re-size them to a same size?
Thanks.

Have a look at the CImg Library, it's quite easy to use. You can load your bitmap file then use one of the resize function.

Probably a overkill, but you can take a look on ImageMagick.

You should look at G'MIC, a command-line tool to batch image processing operations.
It is even more advanced than ImageMagick's convert tool.
Basically, you can call it like this :
gmic *.bmp -resize 128,128,1,3,3 -outputp resized_
to resize all your bmp images into 128x128 color images, and save them with filenames prefixed by 'resized_'.
G'MIC is available for Linux, Windows and Mac, at : http://gmic.sourceforge.net

Related

How to convert an image from .bmp to .png in c++

Is there any open source C++ library using which I can convert an image present in .bmp format to .png . I went through libpng didn't find any way to do it there, while boost/gil looks complex don't know that can be used to do this job.
Maybe this can help you solve the problem: LodePNG
I did not see BMP in boost/GIL.. maybe take a look at Magick++ ImageMagick API
http://www.imagemagick.org/Magick++/tutorial/Magick++_tutorial.pdf
Also GDK-Pixbuf can certainly do this
I use CImg for all my image manipulation. Well written, with good documentation.

Saving frames in opencv without compression

I'm trying to use the imwrite() OpenCV function. I want to save the frames with the .TIFF extension. The problem that I have is that the saved images are compressed so I can't use them. Any idea how I can escape this compression?
thanks in advance
Do not mind what sietschie says. The TIFF flag is hardcoded in the opencv binaries with a LZW compression. You can just turn this off (comment it out) or change it.
In:
3rdparty/libtiff/tiff.h
Remove this line:
#define COMPRESSION_LZW 5 /* Lempel-Ziv & Welch */
Then compile. Presto.
Tiff options other than that are automatically set (8 bit, 16bit, color, rgb, rgba,etc) depending on your image
According to the documentation OpenCV only exposes a limited set of options for writing image files.
Non of which belongs to TIFF-Files.
So unless you want to use your own function or modify the OpenCV source, this is not possible.
I would suggest using another uncompressed format for saving the frames like PXM or BMP, unless you have some specific reasons to use TIFF-Files.
cv::imwrite("imagen.TIFF", bayer, {cv::IMWRITE_TIFF_COMPRESSION, 1,
cv::IMWRITE_TIFF_XDPI, 72,cv::IMWRITE_TIFF_YDPI,72});
The simplest way is recompiling OpenCV or direct using libtiff, but I consider as not very good idea changing 3rdparty/libtiff/tiff.h: after this modification you can't save compressed TIFFs at all with OpenCV, and under non-windows systems you usually have separate libtiff (not as a part of OpenCV).
I suggest simpler approach (still OpenCV recompilation, but you save possibility of writing compressed tiff and don't change libtiff directly):
saving uncompressed TIFFs with OpenCV

How can I draw a png ontop of another png?

How can I "draw"\"merge" a png top of another png (background) using libpng, while keeping the alpha section of the png being drawn on top of the backhround png. There does not seem to be any tutorials or anything mentioned in the documentation about it.
libpng is a library for loading images stored in the PNG file format. It is not a library for blitting images, compositing images, or anything of that nature. libpng's basic job is to take a file or memory image and turn it into an array of color values. What you're talking about is very much out of scope for libpng.
If you want to do this, you will have to do the image composition yourself manually. Or use a library that can do image composition (cairo, etc).

c++ read image pixels

I want a c++ Code to read every pixel from an image file. and i want to save the pixels like:
r[]
g[]
b[]
does somebody know how to do this?
The answer depends on the format of the image file. Is it a format which contains raw RGB data (such as uncompressed TGA)? Is it a YUV image? Is it a compressed image such as JPEG or PNG?
There are already plenty of C++ libraries out there which can read a wide variety of image file formats, and then provide the pixel-level access you require. Take a look at Adobe's GIL, or CImg for example.
There are many freely available libraries for reading different image file formats. Since you're using C++ you might want to look at Adobe's Generic Image Library (GIL) or even OpenCV.
This will sort you out, very easy to use and 'low level' image library:
http://easybmp.sourceforge.net/
Two libraries that I've used that jump to mind are:
ImageMagick
libGD
These libraries can handle a wide variety of image formats, depending on what you need.

Take advantage of Flash CS4's PNG Compression, but as an external file?

Here's the issue: I'm developing some Flash web sites and really enjoying AS3.
The problem: PNG 24-bit images are too big... I have three PNG images with transparency that I'd like to rotate through on the "Home page" every 10 seconds or so. Great. No problem - but instead of embedding all three PNGs in the SWF, which would take the thing longer to load, I'd like to load them dynamically from external files, so that the user doesn't have to wait around for images to load that aren't going to be displayed for another 10-15 seconds anyway. That's fine... I have working code for that.
The real problem: These PNG sizes, even loaded from external files on the fly, are really bugging me. One image is 350k when saved with Photoshop - 300k when I use PNGOUT. But... when I import the PNG into Flash's Library, I can go in and set it to JPG/Image Compression which reduces the size to about 45k, yet maintains the alpha information!! If Flash can compress my PNG that much, and still make it look good, why can't I find an app that can do the same for an external file? I'd be content to load my images into the Flash library and let it handle the compression, but if I end up with 5 or 6 images, that still turns out to be too long of a loading time.
Summary: How can I shrink my 350k PNG image with transparency down to 45k like Flash does when I import it into it's library?
Possible solution: Or.... hmmmm.... this could be a workaround... maybe I could just make a separate SWF movie for each PNG I want to use which uses the Flash compressed image - then read that file dynamically using a Loader... That ought to work! I shall return and report...
But still, how does Flash compress those PNGs so much more than compressors like PNGOUT? Maybe I'm just not passing in the right parameters for them to be effective.
Thanks for reading my ramblings. You all are a great sounding board!
PNG compression is lossless, so it can't compete with lossy perceptual compression schemes as JPEG. Just be sure that your png are the size to be displayed (or not : one trivial "compression" scheme would be to save your image scaled down and zoom it when displaying, but this is normally unsatisfactory). If you can't go below 24-bits (you cant go to a 256-pallete, I guesss) I dont think much can be done. I can only suggest to give a look at PngCrush.
I used to have the same question, but later, I think flash used JPEG compress for PNG files. The JPEG-compressed "png" is actually a variant that standard png format does not support, but flash supports. In my own flash project, I used it a lot. I even used swftools to generate an animated SWF from a lot of png, so I can load the single "png gallery" swf and use all the pngs inside.
I know that the question is a year old, but I thought it would be good for future reference. Using any of the png compression tools (PngCrush, Optipng) will not get anywhere near the same results as Flash compression.
The best way I've found to use flash compression without creating each swf in the Flash IDE is using SwfTools' png2swf utility, it will keep alpha channels and also allow you to set the jpeg's compression quality.
http://www.swftools.org/png2swf.html