Does PIL ImageEnhance library supports 16 bit JPG images - python-3.x

I am trying to save and display 16 bit JPG image. but getting error like
image has wrong mode
.
If Supported, then what will be the mode?

Check this
The mode (this is a string specifying the pixel format used by the image) of an image defines the type and depth of a pixel in the image. The current Python Imaging Library release only supports the following standard modes:
1 (1-bit pixels, black and white, stored with one pixel per byte)
L (8-bit pixels, black and white)
P (8-bit pixels, mapped to any other mode using a colour palette)
RGB (3x8-bit pixels, true colour)
RGBA (4x8-bit pixels, true colour with transparency mask)
CMYK (4x8-bit pixels, colour separation)
YCbCr (3x8-bit pixels, colour video format)
I (32-bit signed integer pixels)
F (32-bit floating-point pixels)
This may be the reason you are getting the above error.
The Image.convert method creates, from an existing image, a new image with a given mode.
To know more about image attributes check the link and about full concept check the link.
Hope this helps you.

Related

UWP - Black color instead of transparency

This is an issue for xamarin.uwp and FFImageLoading, but it reproduces only in UWP.
The issue with optimized files by Photoshop.
I optimized my images on a server with Photoshop. I exported them with option Smaller File (8-bit) after it I got black color in UWP (ios and android are ok).
When I deleted downsample parameters for CachedImage(FFImageLoading control) then transparency was back.
Example:
And files before optimization and after it
https://github.com/luberda-molinet/FFImageLoading/wiki/Xamarin.Forms-API
Says that the CachedImage class does not support transparency on iOS or Windows Phone. Perhaps since the article was written iOS support has been added but not yet UWP.
It's a bug, please make a separate issue on project site. It's related to this:
8 bit PNG can have no more than 256 colors. A part of the PNG file structure holds pointers to 256 colors and then each pixel in the image gets its color from one of those pointers. Thus each pixel only consumes one bytem its 0-255 value pointing to its color on the palette. On the other hand, a 32 bit PNG is 4 bytes per pixel and each pixel can represent a different ARGB color value.
Pixel Format
// Edit I created it: https://github.com/luberda-molinet/FFImageLoading/issues/986

jpeg binary file header with inverted width & height

I am calculating a jpg file size by parsing it as a binary file with nodejs.
But the computed width height gives 4032x3024 when the actual size is 3024x4032.
Its header 0xFFC0 block is as follow:
ffc0 0011 080b d00f c003
According to JPEG format, sizes should be :
height = 0bd0 (i.e:3024)
width = 0fc0 (i.e:4032)
(Using Imagemagick identify program confirms this calculation:
identify HJ7XFd9le.jpg
HJ7XFd9le.jpg JPEG 4032x3024 4032x3024+0+0 8-bit sRGB 380KB 0.000u 0:00.000)
But when viewing the image in my mac viewer, the inspector indicates a size of 3024x 4032!
How can i compute the correct size programmatically by parsing the file as a binary file?
Thanks!
Ah - it's not that the size is inverted, it's that you need to respect the EXIF orientation (rotated 90/270). The sensor is in a certain orientation and if you capture the image rotated, the camera software may signify the change by putting a non-0 orientation in the APP1 EXIF data. – BitBank

How to change the Geometry of bmp image

I am unable to change the geomentry of a bmp image.
I am using Imagemagick libraray in ubuntu.
I have a image with geometry 268*78 i want to convert it to 384*78. I am using the command convert out.bmp -monochrome -resize 384x78 out3.bmp. The command doesn't throw any error but the out3.bmp geometry doesnt change. can anyone tell me a way to change that.
From the imagemagick website:
widthxheight Maximum values of height and width given, aspect ratio
preserved.
Try:
widthxheight! Width and height emphatically given, original aspect
ratio ignored.
convert out.bmp -resize 384x78! -monochrome out3.bmp

color blending with GDI+

I am refering to a older question saying color blending with GDI+
Using GDI+ with Windows Forms, I want to be able to draw with a pen and blend color based on the destination pixel color.
For example, if I draw a line and it passes over black pixels, I want it to be a lighter color (like white for example) so that it's visible. When that same line passes over white pixels, it should be a darker color (black for example) so that it's still clearly visible.
the answers says to use a color matrix for transformation
so i started implementing it..
My image is present in raw data format in rgb48
Gdiplus::Bitmap image(input.width,input.height,input.width*6,PixelFormat48bppRGB,(unsigned char*)rgb48);
Gdiplus::Image *images= image.GetThumbnailImage(input.width,input.height);
Gdiplus::TextureBrush brush(images);
Gdiplus::Pen pen(&brush);
Gdiplus::ColorMatrix matrix={
-1.0f,0.0f,0.0f,0.0f,0.0f,
0.0f,-1.0f,0.0f,0.0f,0.0f,
0.0f,0.0f,-1.0f,0.0f,0.0f,
0.0f,0.0f,0.0f,1.0f,0.0f,
1.0f,1.0f,1.0f,0.0f,1.0f,
};
Gdiplus::Graphics gfx(&image1);
Gdiplus::ImageAttributes imageAttr;
imageAttr.SetColorMatrix(&matrix);
gfx.DrawImage(images,Gdiplus::Rect(0,0,input.width,input.height),0,0,1024,1024,Gdiplus::UnitPixel,&imageAttr);
I am not getting what i expect..Can some one help me in finding the mistake i m doing.
You can use the alpha component of a color to specify transparency, so that colors can be combined. However, if you want the combination to be something other than the alpha blend, you must draw the pixels yourself. You could first draw into a transparent bitmap, then render that onto the destination pixel by pixel.

How can i force the imagemagick module of nodejs to output one single image only?

I am using the imagemagick module with Nodejs
im = require('imagemagick');
The imagemagick module uses the imagemagick command line tools.
I use the convert method to crop an image
im.convert([image_path, '-crop', '200x150', '-gravity', 'center', target_path],
function(err, stdout){}
);
This results in two images. The one with the cropped image area - the second with the image garbage i tried to get rid of.
How can i force imagemagick to output one image file only?
Per the imagemagick documentation for cropping, which is admittedly a little obtuse (emphasis added):
The width and height of the geometry argument give the size of the image that remains after cropping, and x and y in the offset (if present) gives the location of the top left corner of the cropped image with respect to the original image.
...
If the x and y offsets are present, a single image is generated, consisting of the pixels from the cropping region.
...
If the x and y offsets are omitted, a set of tiles of the specified geometry, covering the entire input image, is generated.
... so, you just need to specify your x and y offsets as part of your geometry argument, like so: 200x150-100-75
Notice that I've specified -100 and -75 for the upper left corner of your crop region, this is because you set your gravity to center, but it appears that imagemagick tries to intelligently determine the appropriate distance target based on your gravity, and I don't see exactly how it behaves when you choose center. So you may have to play around with this one a bit, or you could omit the gravity and use the actual offset from the top left corner of your original image.
I had to use the +delete parameter to remove the last image from the image sequence.
im.convert([image_file.path, '-crop', geometry, '+delete', thumb_path], ...

Resources