cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Doubt about values returned by read_imagef

The values returned by read_imagef are in the range 0 to 1 whereas the pixel intensity range is from 0 to 255... i want to do further processing on the intensity values to do Image Segmentation which is based only on the intensity values (Operations carried out would be like finding difference between two intensity values, sorting, finding minimum, shuffling etc). How to get these values in the range 0 to 255 in an integer form(for convenience)...? Can I just multiply every value with 255 or is there something else I need to do...?

0 Likes
1 Solution

Didn't you forget change size of memory pointer passed to clCreateImage()?

View solution in original post

0 Likes
15 Replies
himanshu_gautam
Grandmaster

This probably depends on the attribute you have given to the sampler. I thin the values are getting "normalized".

Multiplying by 255 is also a good option (or) look at changing the args whle creating sampler

Just browse the OpenCL Spec on related topics -- you should be able to hit it.

Actually I know about the sampler data type...! Its declared as :

clCreateSampler(context,

                              CL_FALSE, // Non-normalized coordinates

                              CL_ADDRESS_CLAMP_TO_EDGE,

                              CL_FILTER_NEAREST,

                              &errNum);

For non-normalized co-ordinates we give CL_FALSE, but even then it gives in the range 0 to 1...! If I give CL_TRUE which might be for normalized co-ordinates it gives the same answer...! What can be done to non-normalize it actually...?

0 Likes

Can you ZIP and post a repro-case here?

I will check out and let you know.

0 Likes

Repro-case...? whats that..?

0 Likes

hey Himanshu,

  I dint get you by repro-case, please tell me what does that mean, so that I cud giv u relevant information...!

0 Likes

I have posted my code in the zip file attached... Please do see and reply to my doubt...!

0 Likes

Repro --> Reproduce

A Repro-case is usually a self-contained compilable unit - which can be run to reproduce the problem.

Will take a look by Friday.

0 Likes

I read about how to get the intensity values in a non- normalized way.The channel data-type of the image needs to be specified as CL_FLOAT instead of CL_UNORM_INT8, if the channel order of the image is CL_RGBA. I specified this in my code but it is giving a runtime error saying.. "Unhandled exception at 0x541e7802 in ImageFilter.exe: 0xC0000005: Access violation reading location 0x03e41000." and this error occurs just after I ve specified CL_FLOAT while creating the image object.

now what can be the fault...? the code is same as I ve uploaded above, just I ve made a change for the channel datatype as CL_FLOAT...!

0 Likes

Hey... I am glad you experimented and explored. Way to go. Will check next week.

0 Likes

Didn't you forget change size of memory pointer passed to clCreateImage()?

0 Likes

Oh yeah I changed the size from char to float but the intensity values given are some garbage values.  I have given the output below as the image captured of the cmd window..!clFloat doubt.PNG

0 Likes

The binary representation of a floating point numbers are very different from integers -- although both occupy 4 bytes.

If you are populating the image with "integer" data -- then you will definitely have a problem.

Anyway, I am downloading your project now. Will let you know..

Also, You can use CL_UNSIGNED_INT8 along with CL_RGBA and get unsigned non-normalized values from 0 to 255 -- as you desired earlier.

0 Likes

Shreedhar, Did you try CL_UNSIGNED_INT8?

0 Likes

For using CL_UNSIGNED_INT*, I think I'll have to change read_imagef to read_imageui...

0 Likes

Yeah, As I understand you wanted values from 0 to 255. So, you can use a read_imageui and you should be good to go. Does that help?

0 Likes