Converting char to float to use in image processing.

Hello, I am currently reading images stored in the targa file format so that I can apply some kind of filters on it. For instance, I read the test image and then try to apply the mean filter on it. In this case I want to multiply the value of every pixel that will take part of the determination of the value of a certain pixel by 1/9. The problem is that when I read the image from the disk I read a bunch of char values.
And if I try to multiply a char by 1/9, I end with zero, and so with full black image.
So I decided to convert it to float to do the processing and then convert back to char in the writing time. The problem is that the char to float method is not working. For example:
1
2
3
char tmp = 100;
float teste = a1_9 *  (float) (tmp);
cout << "Teste float: "<< teste << endl;


And the result is always zero which means a black image.

Am I understanding it wrongly? How should I convert the char to float to that I can calculate de average? Thanks for the attention.
What is a1_9 ?
i.e. What type is it and what value does it have?

1
2
3
4
	float a1_9 = 1.0f/9.0f;
	char tmp = 100;
	float teste = a1_9 *  tmp;
	cout << "Teste float: "<< teste << endl;

Teste float: 11.1111


Note, this doesn't work,
1
2
    // correct value 0.111111 truncated to 0
    char a1_9 = 1.0f/9.0f;    

Nor does this,
1
2
3
    // integer division. 1 and 9 are integers, 
    // so 1/9 is integer 0
    float a1_9 = 1/9;     
Last edited on
It is a float. I was dividing two integers. Thanks for the correction.
Topic archived. No new replies allowed.