PGM image handling [closed]
Is there a way to convert a non pgm format image to pgm format and then to store it in a Mat array without saving it in the file system?
Is there a way to convert a non pgm format image to pgm format and then to store it in a Mat array without saving it in the file system?
Asked: 2012-10-26 16:00:22 -0600
Seen: 2,389 times
Last updated: Oct 26 '12
Area of a single pixel object in OpenCV
build problems for android_binary_package - Eclipse Indigo, Ubuntu 12.04
OpenCV DescriptorMatcher matches
Can't compile .cu file when including opencv.hpp
Using OpenCV's stitching module, strange error when compositing images
compile error in opencv2/flann/lsh_table.h when compiling bgslibrary
Do you want to convert a non-pgm to pgm in RAM? Sounds a bit strange... What prevents you from loading a pgm with
imread
, and exporting it withimwrite
as other format?imdecode() and imencode() may be your friends. But note that it doesn't make much sense to store an encoded image in a Mat array() - it's useless.
May be my question is not clear. Loading a pgm with imread works just fine but imread needs the location of the pgm image in the file system. I can always load a jpg image and save it as pgm image and then load the pgm image using imread to achieve what I want. But what I am thinking here is to avoid saving the pgm image in the local file system. Instead I would like to use jpg image to convert to pgm and without saving the pgm image in the file system, I would like to load it using imread/any other method to a Mat array
Sammy - just curious why do you think it is useless? If I have to process 1,000,000 jpg images, I dont want to waste my disk space for saving 1,000,000 pgm images.
It's not clear what you want to do with all those PGM images. pgm is a format that you use to save images on disk. If you want to process them, you have to decode them - from jpg, pgm, bmp or any other image file format, and keep them in a matrix.So it's not clear what could you do with your images: load from jpg (and decode), then encode to png, then decode back to Mat and process? If you are more specific about what you're trying to accomplish, we could help you better.
I have this function call that takes a matrix of pgm format image. I have a jpg format image. I dont want to convert and save the jpg image to the file system as pgm and then load it to the matrix. Instead I want to convert jpg image to pgm matrix.
I think you should take a look at the basics of image processing. There is no such thing like pgm matrix. PGM is a binary file format, and you cannot access the image pixels unless you decode it into a matrix, in the same way you decode any other file format, like jpg. It makes absolutely no sense to keep png images in memory, or try to process them. It is only for storage purposes, or (in some cases) as a way to package images before sending them through a network. And if for whatever reasons you have this function that takes a pgm blob, you have to convert your jpg images to matrix (imread or imdecode) then imencode() them to png. But that function will decode them back to process them.