pypng | Pure Python library for PNG image | Image Editing library
kandi X-RAY | pypng Summary
kandi X-RAY | pypng Summary
PNG module for Python. PyPNG is written entirely in Python.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Read the image
- Process a PNG file
- Returns the chunk length and type of the chunk
- Calculate the palette
- Save the table to a file
- Write pixel data to file
- Write rows to outfile
- Write a PNG file
- Write a chunk to a PNG file
- Validate colour
- Check if x is a natural number
- Process the IHDR chunk
- Validate bitdepth and colortype
- Convert png into an output file
- Print ICC tag table
- Convert a string to its hex representation
- Open a file - like object
- Generate a profile
- Convert RDF32 to RDF32
- Render a text message
- Parse XYZ number
- Initialize an ICC profile from a file
- Write the tag table
- Write the table to a file
- Return stdout
- Decode CMVideoCardGammaType
pypng Key Features
pypng Examples and Code Snippets
Community Discussions
Trending Discussions on pypng
QUESTION
I want to create a PNG image file with palette information in Python using Pillow and/or pypng.
The input is:
Palette information
...
ANSWER
Answered 2021-Jun-14 at 09:38Here's some demonstration code to convert an existing RGB image to some indexed color image. Please keep in mind, that Pillow only allows storing 256 different colors in some color palette, cf. Image.putpalette
. So, make sure to have your input images not containing more than 256 different colors.
Also, I will assume, that the palette is known before, and that all colors in the existing RGB image are exclusively from that palette. Otherwise, you'd need to add code for extracting all colors, and setting up a proper palette beforehand.
QUESTION
I'm trying to save a 16-bit numpy array as a 16-bit PNG but what I obtain is only a black picture. I put here a minimum example of what I'm talking aboout.
...ANSWER
Answered 2020-Sep-24 at 17:50It looks like imageio.imwrite
will do the right thing if you convert the data type of the array to numpy.uint16
before writing the PNG file:
QUESTION
Ok, so I just started python and I need to convert an image to 4bpp for a tool, and I came across pypng, but I couldn't find how to only convert to a bit depth of 4, so this is my result from looking at a few dozen examples:
...ANSWER
Answered 2020-Jul-07 at 04:03If you need 4bpp
then you should use bitdepth=4
and you have to create array
with values 0..15
(for greyscale image) and also array with 16 values (R,G,B)
for palette
(for color image)
I use PIL
to load RGB
image and convert to image with 16 colors/indexes to palette with 16 colors (RGB
)
QUESTION
I'm trying to write a python script that takes in standard 24-bit pngs and converts them to 8-bit pngs for better compression. It looks like pypng can do this but I can't quite figure out how to use it. Image manipulation is a new area for me so this may seem silly. I have this currently:
...ANSWER
Answered 2020-May-26 at 12:38Original Answer
I think this does what you ask:
QUESTION
I can't wrap my head around how to dockerize existing Django app. I've read this official manual by Docker explaining how to create Django project during the creation of Docker image, but what I need is to dockerize existing project using the same method.
The main purpose of this approach is that I have no need to build docker images locally all the time, instead what I want to achieve is to push my code to a remote repository which has docker-hub watcher attached to it and as soon as the code base is updated it's being built automatically on the server.
For now my Dockerfile looks like:
...ANSWER
Answered 2017-Nov-13 at 18:14This question is too broad. What happens with the Dockerfile you've created?
You don't need docker compose unless you have multiple containers that need to interact.
Some general observations from your current Dockerfile:
- It would be better to collapse the pip install commands into a single statement. In docker, each statement creates a file system layer, and the layers in between the pip install commmands probably serve no useful purpose.
- It's better to declare dependencies in setup.py or a requirements.txt file (
pip install -r requirements.txt
), with fixed version numbers (foopackage==0.0.1
) to ensure a repeatable build. - I'd recommend packaging your Django app into a python package and installing it with pip (
cd /code/; pip install .
) rather than directly adding the code directory. - You're missing a statement (CMD or ENTRYPOINT) to execute the app. See https://docs.docker.com/engine/reference/builder/#cmd
QUESTION
I currently have a .h5 file containing grayscale imagery. I need to convert it to a .jpg.
Does anybody have any experience with this?
Note: I could possible convert the h5 file to a numpy array and then use an external library like pypng to convert that to a png. But I am wondering if there is a more efficient way to convert to an image, and preferrably a .jpg.
...ANSWER
Answered 2018-Nov-30 at 14:06Key ingredients:
h5py to read the h5 file. Determine the format of your image and use PIL.
Let us suppose it's RGB format (https://support.hdfgroup.org/products/java/hdfview/UsersGuide/ug06imageview.html)
Suppose your image is located at Photos/Image 1 then you can do.
QUESTION
ANSWER
Answered 2019-Dec-05 at 15:46Given all the new information I am updating my answer with a few more tips for debugging the issue.
I found a site here which creates sample transparent images. I created a 64x64 cyan (R=0, G=255, B=255) image with a transparency layer of 0.5. I used this to test your code.
I read in the image two ways to compare: im1 = cv2.imread(fileName)
and im2 = cv2.imread(fileName,cv2.IMREAD_UNCHANGED)
. np.shape(im1)
returned (64,64,3)
and np.shape(im2)
returned (64,64,4)
. This is why that flag is required--the default imread settings in opencv will read in a transparent image as a normal RGB image.
However opencv reads in as BGR instead of RGB, and since you cannot save out with opencv, you'll need to convert it to the correct order otherwise the image will have reversed color. For example, my cyan image, when viewed with the reversed color appears like this:
You can change this using openCV's color conversion function like this im = cv2.cvtColor(im, cv2.COLOR_BGRA2RGBA)
(Here is a list of all the color conversion codes). Again, double check the size of your image if you need to, it should still have four channels since you converted it to RGBA.
You can now add your noise to your image. Just so you know, this is also going to add noise to your alpha channel as well, randomly making some pixels more transparent and others less transparent. The random_noise function from skimage converts your image to float and returns it as float. This means the image values, normally integers ranging from 0 to 255, are converted to decimal values from 0 to 1. Your line img = Image.fromarray(noise_img, 'RGB')
does not know what to do with the floating point noise_img. That's why the image is all messed up when you save it, as well as when I tried to show it.
So I took my cyan image, added noise, and then converted the floats back to 8 bits.
QUESTION
Sorry about the long post in advance.
Using Python 3.7.3, I want to have base64 encoded photo and resize it without saving to file to disk and reopening the file using Image.open().
I've looked into PyPng from This answer which seems to use the base64 data directly but I can't figure out how to resize it as a PIL Image. I know how to resize it, once it's a Pillow Image, what I need to figure out is how to get from base64 directly to a Pillow Image.
...ANSWER
Answered 2019-Sep-19 at 20:23Found the answer thanks to this Post which led me to ImageTk.PhotoImage:
QUESTION
Kitti has a benchmark for Optical Flow. They require the flow estimate to be 48bit PNG files to match the format of the ground truth files they have.
Ground Truth PNG Image is available for download here
Kitti have a Matlab DevKit for the estimate versus ground truth comparison.
I want to output the flow from my network as 48 bit integer PNG files, so that my flow estimates can be compared with other Kitti benchmarked flow estimates.
The numpy scaled flow file from the network is downloadable from here
However, I'm having trouble converting the float32 3D array flow to 3 channel 48bit files (16bit per channel) in python because there doesn't seem to be the support for this among image library providers, or because I am doing something wrong with my code. Can anyone help ?
I have tried a bunch of different libraries and read lots of posts.
Scipy outputs a png that is only 24bit unfortunately. Output flow estimate png generated using scipy available here
...ANSWER
Answered 2019-Aug-02 at 02:59Here is my understanding of what you want to do:
- Load the data from
Scaled_Flow.npy
. This is a 32 bit floating point numpy array with shape (2, 375, 1242, 2). Convert
Scaled_Flow[1]
(an array with shape (375, 1242, 2)) to 16 bit unsigned integers by:- multiplying by 64,
- adding
2**15
, and - casting the values to
np.uint16
.
That is the inverse of this description that you quoted: "To convert the u-/v-flow into floating point values, convert the value to float, subtract 2^15 and divide the result by 64.0".
- Increase the length of the third dimension from 2 to 3 by concatenating an array of all 1s.
- Save the result to a PNG file.
Here's one way you can do that. To create the PNG file, I'll use numpngw
, a library that I wrote for creating PNG and animated PNG files from numpy arrays. If you give numpngw.write_png
a numpy array with data type np.uint16
, it will create a PNG file with 16 bits per channel (i.e. a 48 bit image in this case).
QUESTION
I'm trying to set up a Python 3 environment that has access to the png module. When I list the installed packages, I get this:
...ANSWER
Answered 2018-Aug-01 at 19:27The conda package, sssdgc::png
seems to be libpng12:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pypng
PyPNG is pure Python and has no dependencies. It requires Python 3.5 or any compatible higher version.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page