Hello developers,
I have little question:
I simply want to create and save a 32-bit tif picture(Gray), set some pixels, save it and find these pixels in the resulting image(for further calculations).
Environment:ImageMagick 6.4.8 with QDepth 32 and HDRI and Visual Studio.
Now I use:
list<Image> imageList;
readImages( &imageList,"image.tif" );
Quantum value=0.84;
for(..){
imageList.front().pixelColor(posX,posY,Color(value,value,value));
}
writeImages( imageList.begin(), imageList.end(), "image_done.tif" );
Two things are dissappointing:
1. It only works when I create a 32-bit tif image by another software, save this image, and load it with IM.
When I use "Image image(Geometry(sizeX,sizeY), Color(MaxRGB,MaxRGB,MaxRGB,0));" to dynamically configure the size, the values of the pixels are totally wrong(I guess result of some scaling processes).
I want to create the image with IM rather than with another image program.
2. Due to QDepth 32 and HDRI the values set by "pixelColor" seem to be scaled before putting into the image.I (thought I) proudly found out that with a multiplication of these values by "pow(2.0,32)" the "real" value will be written into the image-file.
Today I found out that some values (for example 0.84 and some more) are written as wrong stuff like -6,8734e8 into the file and
I have absolutely no idea why (btw. -0.84 works!!!)!
The reason might be related to those scaling processes, too.
Maybe somebody understands this phenomenon.
Thanks for every suggestion!
Create and save 32-Bit tif picture with magick++
Re: Create and save 32-Bit tif picture with magick++
Pixels and colors are scaled to the quantum depth of the ImageMagick distribution. Since you have HDRI enabled you do not need Q32, instead use Q16 or Q8. For 32-bit TIFF output you need to specify the image depth as 32 and if you want to affect how the pixel values are stored set image options found under the TIFF tag on this page: http://www.imagemagick.org/script/formats.php. It says:
Only you will use Magick++ to set the options, defineValue() or defineSet(), rather than the command-line -define option. If you have problems getting this to work, create a source module that gets you close to what you want and post it here. We'll download it and modify it to produce the type of TIFF image you are looking for. We will then use your example in the ImageMagick documentation to save other users time when they want to create HDRI TIFF images from Magick++.Use -define to specify the rows per strip (e.g. -define tiff:rows-per-strip=8). To define the tile geometry, use for example, -define tiff:tile-geometry=128x128. To specify a signed format, use -define quantum:format=signed. To specify a single-precision floating-point format, use -define quantum:format=floating-point. Set the depth to 64 for a double-precision floating-point format. Use -define quantum:polarity=min-is-black or -define quantum:polarity=min-is-white toggle the photometric interpretation for a bilevel image. Specify the extra samples as associated or unassociated alpha with, for example, -define tiff:alpha=unassociated.
Re: Create and save 32-Bit tif picture with magick++
Thank you for your reply.
The basic solution I'am looking for is as follows:
A vector of data is to be demonstrated in a 32-Bit tif file (Grays).
The values are floating point values ("double").
A tif file is to be created with 32-Bit depth and diverse dimensions.
#define Quantum depth 32
#define HDRI
/*START CODE*/
#include <Magick++.h>
#include <iostream>
#include <vector>
#include <stdio.h>
#include <math.h>
using namespace std;
using namespace Magick;
....
....
....
void plotValues(vector<vector<double>> valueVector, string filePath)
{
//Get dimensions
int imageHeigth=valueVector.size();
int imageWidth=valueVector[0].size();
//Create tif image object
Image my_image(Geometry(imageWidth,imageHeigth, "tif",32,"float"));
for(int row=0;row<imageHeigth;row++)
{
for(int column=0;column<imageWidth;column++)
{
if(valueVector[row][column]!=-1)
{
//Set the pixels in the image object
my_image.setPixelValue(valueVector[row][column]);
}
}
}
//Save the image on harddisk for analysis
filePath.append("\\complete.tif");
my_image.write(filePath);
}
/*END CODE*/
Some parts are imaginary for showing the needs.
I believe that such a operation (setting values in a tif-image) will help several developers.
Demonstrating calculated values in an image is an awesome way to interpret the data.
Thank you very much for your support!
The basic solution I'am looking for is as follows:
A vector of data is to be demonstrated in a 32-Bit tif file (Grays).
The values are floating point values ("double").
A tif file is to be created with 32-Bit depth and diverse dimensions.
#define Quantum depth 32
#define HDRI
/*START CODE*/
#include <Magick++.h>
#include <iostream>
#include <vector>
#include <stdio.h>
#include <math.h>
using namespace std;
using namespace Magick;
....
....
....
void plotValues(vector<vector<double>> valueVector, string filePath)
{
//Get dimensions
int imageHeigth=valueVector.size();
int imageWidth=valueVector[0].size();
//Create tif image object
Image my_image(Geometry(imageWidth,imageHeigth, "tif",32,"float"));
for(int row=0;row<imageHeigth;row++)
{
for(int column=0;column<imageWidth;column++)
{
if(valueVector[row][column]!=-1)
{
//Set the pixels in the image object
my_image.setPixelValue(valueVector[row][column]);
}
}
}
//Save the image on harddisk for analysis
filePath.append("\\complete.tif");
my_image.write(filePath);
}
/*END CODE*/
Some parts are imaginary for showing the needs.
I believe that such a operation (setting values in a tif-image) will help several developers.
Demonstrating calculated values in an image is an awesome way to interpret the data.
Thank you very much for your support!
Re: Create and save 32-Bit tif picture with magick++
Quick question. Have you read "The Pixel Cache: getting indirect access to an image canvas" from http://www.imagemagick.org/Magick++/tut ... torial.pdf?
Re: Create and save 32-Bit tif picture with magick++
Yes I have read this tutorial.
You mean I should use the:
Image my_image( 800, 600, "GRAY", 4, pixels );
-constructor?
"The pixels will be normalized [0..1]"
Do you think I have to de-normalize the pixels?
I don't want pixels from 0-1 but the "real" pixelvalue.
And then save:
my_image.magick("tif");
my_image.write("file_name_no_extension");
I going to try this.
THX
You mean I should use the:
Image my_image( 800, 600, "GRAY", 4, pixels );
-constructor?
"The pixels will be normalized [0..1]"
Do you think I have to de-normalize the pixels?
I don't want pixels from 0-1 but the "real" pixelvalue.
And then save:
my_image.magick("tif");
my_image.write("file_name_no_extension");
I going to try this.
THX
Re: Create and save 32-Bit tif picture with magick++
Oh no this does not work..I need an image to allocate the pixelcache.
I guess that I need some help to pass this challenge.
I found out that as a secondary effect, the "imageList.front().pixelColor(posX,posY,Color(value,value,value));" approach will cause serious memory problems.
Computer runs out of memory (4GB available).
I want to find a better solution.
Thank you.
I guess that I need some help to pass this challenge.
I found out that as a secondary effect, the "imageList.front().pixelColor(posX,posY,Color(value,value,value));" approach will cause serious memory problems.
Computer runs out of memory (4GB available).
I want to find a better solution.
Thank you.