Is it reasonable to scale down (resize) a jpeg by operating on each MCU independently? - jpeg

I’m writing software for a cortex m4 microcontroller. I’d like to resize a jpeg image - given as an example a jpeg image with MCUs of 16x16/256 pixels. Is it reasonable to reduce each MCU down to an arbitrarily smaller MCU? Say from 16x16 to 1x1 or 2x2 or 3x3. My thinking was that I could merge/average the color information among the 256 pixels until I’ve reduced the MCU to my desired size. Is this reasonable or naive way of resizing my image.
I’ve started thinking through this problem and would like some advice on thoughts for my approach.

Related

How to detect image brightness and sharpness in python?

I tried applying tesseract ocr on image but before applying OCR I want to improve the quality of the image so that OCR efficiency increase,
How to detect image brightness and increase or decrease the brightness of the image as per requirement.
How to detect image sharpness
It's not easy way to do that, if your images are similar to each other you can define "correct" brightness and adjust it on unprocessed images.
But what is "correct" brightness? You can use histogram to match this. See figure bellow. If you establish your correct histogram you can calibrate other images to it.
Richard Szeliski, Computer Vision Algorithms and Applications
I think you can use the autofocus method. You must check contrast histogram of image and define what is sharp to you.
source
*Basic recommendation, using the gray images is better on OCR
You can use the BRISQUE image quality assessment for scoring the image quality, it's available as a library. check it out, a smaller score means good quality.

openGLES 2 - How do I load a texture with 8-bit grayscale and 8-bit alpha, without expanding to 32-bit RGBA?

We're trying to optimize memory usage in our program, and we've noticed that some of our textures could be stored as greyscale with an alpha value as when stored as RGBA the RGB values are all the same.
We'd like to save disk space as well as memory by only needing to store 2 channels: greyscale and alpha, both 8-bit. Thus providing a 50% saving on both disk and memory over 32-bit RGBA.
However the hurdle we've hit is that we can't work out how to give this info to openGL. We can store the image on disk either as one image with two 8-bit channels, or as two images with one 8-bit channel each. I can't find a way for openGL to see this as a greyscale image so that it only has these two channels in memory without looking at them as being specific colours like Red and Green - as I have found GL_RG8 exists which has the right number of channels at the right bitdepth, but wrong colours.
Is this even possible in openGLES 2? Can we give 2 channels to openGL and tell it that they're not Red and Green but Grey and Alpha?
I have seen this question: Can I use a grayscale image with the OpenGL glTexImage2D function? but that's rather old and GL_LUMINANCE is now depricated.
Note that GL_RG8 only exists on OpenGL ES 3.x upwards; it's not part of OpenGL ES 2.x. For ES 2.x you can use GL_LUMINANCE_ALPHA. It's deprecated, but not removed, so should still work just fine.
If you really want to use GL_RG8 then you can fix "wrong color" either by using swizzles in the shader code to reorder the channels when you use them, or you can swizzle in the sampler by setting TEXTURE_SWIZZLE_[R|G|B|A] using glTexParameteri().
If you don't mind the venial sin I have noticed that every ES2 implementation I have encountered (iOS, Angle, Adreno, Mali, and some other weird Android drivers,) silently support GL_RG8 (for format) (and GL_RG for internalFormat.)

Lossless grayscale JPEG "color" inversion?

Imagemagick can invert the colors of a JPEG like so:
mogrify -negate image.jpg
However, that's not lossless. My intuition says that color inversion should be doable in a lossless fashion, at least for grayscale images, but I know hardly anything about JPEG. Hence my questions:
Is lossless JPEG grayscale inversion possible in theory?
If so, is libjpeg or any other software out there able to do it?
It's not lossless because there is not a 1:1 match between the gamuts of the RGB and YCbCr colorspaces used in JPEG. If you start with an RGB value that is within YCbCR and flip it, you may get a value outside the YCbCr colorspace range that will end up getting clamped.
JPEG encodes images as a series of entropy coded deltas across MCUs (minimum coded units - 8x8 blocks of DCT values) and entropy coded quantized DCT coefficients within each MCU. To do something like inverting the pixel values (even if grayscale) would involve decoding the entropy coded bits, modifying the values and re-encoding them since you can't "invert" entropy coded DCT values. There isn't a one to one matching of entropy coded lengths for each value because the bits are encoded based on the statistical probability and the magnitude/sign of quantized values. The other problem is that the coded DCT values exist in the frequency domain. I'm not a mathematician, so I can't say for sure if there is a simple way to invert the spatial domain values in the frequency domain, but I think at best it's really complicated and likely the quantization of the values will interfere with a simple solution. The kind of things you can do losslessly in JPEG files is rotate, crop and less well known operations such as extracting a grayscale image from a color image. Individual pixel values can't be modified without having to decode and recode the MCUs which incurs the "loss" in JPEG quality.

game background file of just 2KB ...how?

I am making game for mobile phone and i have little knowledge of creating graphics for games. I am making graphics using CorelDraw & Photoshop.
I made flash.png using above 2 software's & could squeeze the size to 47Kb only.....
But I came across one game which has file size just 2kb for its background (bg0 & bg1.png)
I want to know how do I make such beautiful graphics without increasing the size of my file...
I assume the gamer must have hand sketched, scanned & used one of the above software's to fill the colors.....but i am not sure about it...
plz help
There are several ways to reduce the size of a PNG:
Reduce the colour depth. Don't use RGB true/24 bit colour, use an indexed colour image. You need to add a palette to the image, but each pixel is one byte, not two.
Once you have an indexed colour image, reduce the number of colours in the palette. There is a limit to how many colours you can reduce it by - the fewer colours, the lower the image quality.
Remove unnecessary PNG chunks. Art packages may add additional data to the PNG that isn't image data (creation date, author info, resolution, comments, etc.)
Check http://pmt.sourceforge.net/pngcrush/ to get rid of unneeded PNG chunks and compress the IDAT chunk even further. This might help a lot or not at all depending on the PNG that came out of the art packages. If it doesn't help, consider index PNGs. And if you go for paletized PNGs be sure to check out http://en.wikipedia.org/wiki/Color_cycling for cool effects you might be able to use.
Use a paletted png with few colors and then pass the png through a png optimizer like the free exe PngOptimizer
If your png still is too big reduce the number of colors used and reoptimize. Rince and repeat ^^.
I have used this technique on quite a lot of mobile games where size was of the essence.

Imaging Question: How to determine image quality?

I'm looking for ways to determine the quality of a photography (jpg). The first thing that came into my mind was to compare the file-size to the amount of pixel stored within. Are there any other ways, for example to check the amount of noise in a jpg? Does anyone have a good reading link on this topic or any experience? By the way, the project I'm working on is written in C# (.net 3.5) and I use the Aurigma Graphics Mill for image processing.
Thanks in advance!
I'm not entirely clear what you mean by "quality", if you mean the quality setting in the JPG compression algorithm then you may be able to extract it from the EXIF tags of the image (relies on the capture device putting them in and no-one else overwriting them) for your library see here:
http://www.aurigma.com/Support/DocViewer/30/JPEGFileFormat.htm.aspx
If you mean any other sort of "quality" then you need to come up with a better definition of quality. For example, over-exposure may be a problem in which case hunting for saturated pixels would help determine that specific sort of quality. Or more generally you could look at statistics (mean, standard deviation) of the image histogram in the 3 colour channels. The image may be out of focus, in which case you could look for a cutoff in the spatial frequencies of the image Fourier transform. If you're worried about speckle noise then you could try applying a median filter to the image and comparing back to the original image (more speckle noise would give a larger change) - I'm guessing a bit here.
If by "quality" you mean aesthetic properties of composition etc then - good luck!
The 'quality' of an image is not measurable, because it doesn't correspond to any particular value.
If u take it as number of pixels in the image of specific size its not accurate. You might talk about a photograph taken in bad light conditions as being of 'bad quality', even though it has exactly the same number of pixels as another image taken in good light conditions. This term is often used to talk about the overall effect of an image, rather than its technical specifications.
I wanted to do something similar, but wanted the "Soylent Green" option and used people to rank images by performing comparisons. See the question responses here.
I think you're asking about how to determine the quality of the compression process itself. This can be done by converting the JPEG to a BMP and comparing that BMP to the original bitmap from with the JPEG was created. You can iterate through the bitmaps pixel-by-pixel and calculate a pixel-to-pixel "distance" by summing the differences between the R, G and B values of each pair of pixels (i.e. the pixel in the original and the pixel in the JPEG) and dividing by the total number of pixels. This will give you a measure of the average difference between the original and the JPEG.
Reading the number of pixels in the image can tell you the "megapixel" size(#pixels/1000000), which can be a crude form of programatic quality check, but that wont tell you if the photo is properly focused, assuming it is supposed to be focused (think fast-motion objects, like trains), nor weather or not there is something in the pic worth looking at, that will require a human, or pigeon if you prefer.

Resources