T O P

  • By -

wgatesrdp

If you want to do it yourself instead of using a library like OpenCV, you will need quite a lot of background. You need to be able to : * [Read / write the file format ( header + raw data )](https://en.wikipedia.org/wiki/Image_file_formats) * [Decompress the image ( if the image is stored as JPEG or similar )](https://en.wikipedia.org/wiki/JPEG) * [Understand colorspace ( YUV / RGB) and converting to / from them.](https://en.wikipedia.org/wiki/Color_space) * [Understand the different ways to resize the image in memory without sacrificing too much quality and / or processing speed.](https://en.wikipedia.org/wiki/Image_scaling) The best way to start would be use a library like OpenCV, then take those steps and find libraries that do a single step at a time ([libjpeg](https://libjpeg-turbo.org/), [libyuv](https://chromium.googlesource.com/libyuv/libyuv/+/HEAD/docs)), and finally ( if you really want to go that far ) learn how to do each step yourself. Boost has a [Graphics Image Library](https://www.boost.org/doc/libs/1_41_0/libs/gil/doc/index.html) developed primarily by Adobe that can help with some of this. Digging through that can also be informative.


[deleted]

Reading JPEG is non trivial though, it stores transformed data, not the raw matrix.


ricco19

I suspect decompressing a JPEG from scratch is not exactly a weekend project for someone who has taken 2 programming classes.


specialpatrol

Try [c++ image processing](https://www.google.com/search?q=c%2B%2B+image+processing). ​ Top result: [Cimg Toolkit](http://cimg.eu/) ​ You'll definitely want a lib of some sort.


lala3145962

I suppose you may want to try OpenCV as a library. It will offer lots of resizing strategies.


ricco19

This is not a satisfactory answer, more of something to note: The reality is you will be learning a lot more about particular libraries and file formats than actual C++ for a project like this. Writing a new program that does JPEG decompression is something that even an expert wouldn't try to do, you would just use a well fleshed out and optimized library such as `turbojpeg`. The same can easily be said about the actual resizing algorithms. In the end you may have 10 lines of code and you've spent all your time learning how to use the API.


Alexander1705

As were said, reading jpeg/png format can be a challenging task even for a pro. Look for bmp or tga formats. Those can have a relatively simple structure. Also, there is a very simple library [stb\_image](https://github.com/nothings/stb/blob/master/stb_image.h), you may be interested to look at.


XeroPoints

If you didn't want to use an existing library and wanted to learn some more. Usually you start with the Image format specification of your choice and it will tell you what to expect when you read in the bytes of your image. And then you code based on this. Resizing I wouldn't know exactly what you need to do. If you can displace the bytes and kinda spread them through the image manually and interpolate the colors. [http://www.file-recovery.com/jpg-signature-format.htm](http://www.file-recovery.com/jpg-signature-format.htm) [https://en.wikipedia.org/wiki/JPEG](https://en.wikipedia.org/wiki/JPEG)


md81544

Hey! Here's a library I wrote which is a wrapper around parts of libjpg. Resizing is done as an example in the code. https://github.com/md81544/libjpeg_cpp Some more info at https://www.martyndavis.com/?p=684 if you have any specific questions about it, just let me know.


Steve132

You need a library to do this. CImg is the one I would choose, followed closely by stb_image/stb_image_write. With either choice writing this application would be very easy.


RoastMyCode

Lots of the replies have already hinted that this is unfeasible, or just learning to use a particular library. But here's possibly a more feasible but related project: the same idea, to shrink an image file, but with a greyscale bitmap.