Is it always necessary to convert image to double type before further execution?

Hi,
I want to threshold an image. I can read the image and it is a byte type (UINT 8). I want to pass this image to another function as it is but it asks me to convert to double before I can pass to another function where threshold is performed via MEX MATLAB. How can I pass the image as the same data type? Thanks in advance.

Answers (2)

We don't know. You will need to tell us which function you are trying to pass it to.
Well apparently you can't. It said so. It said it wanted double and rejected your call when you tried to pass in uint8(). I don't know why, but that's the way it is. It seems like it could just cast it to double internally, but, for whatever reason, it doesn't. So I guess you have to live with it. Either use double() if it can take whatever range you have, or use im2double() if it wants it in the 0-1 range.

6 Comments

Yes, you are right. I need to remap the image back to 'uint8' for further analysis. Now I am having a problem, like, in reading certain pixel values of an image and copy them to another new image (like image cropping). Thanks.
Well you don't necessarily need to go back to uint8 for analysis - it just depends on what you're doing. I can't help anymore unless you provide more details. For example I have no idea if you're using imcrop() or doing the cropping some other way. I have a copy and paste demo (attached) in case that helps.
There is a routine to convert double precision images into uint8(). Or you can just use
uint8(floor(255 * DoublePrecisionImage))
Actually I have my own data types defined in my header files. The image is defined as byte arrays and has image pointer too. I want to read the images in matlab (in mex) and convert this image to my data type and work from there. I am trying to copy all the pixel values from matlab's image to my own datatype's array of order (no_of_bands * rows * cols) as shown below.
for(bands=0; bands < no_of_bands; bands++)
{
image = getData_Image(next_image, bands); //To work on each band at a time (R-G-B).
for(r=0; r < rows; r++)
{
for(c=0; c < cols; c++)
image[r][c]= matlab_image[r+1][c+1][bands+1]; //image[r][c] is my byte type array.
}
}
My problem is mainly how to access and assign each element of the matlab image because as far as I have understood my problem is in the "matlab_image[r+1][c+1][bands+1];" part of the code. Hope you are getting what I mean and thanks for all your suggestions.
@Krishna: This is not Matlab. We do not know: getData_Image function, type and size of "image", value or "rows" and "cols", size and type of "matlab_image" and why you use 1-based indexing here. So currently there is no chance to guess, what you are doing.
Sorry that it was not clear. Actually 'image' variable is byte-array type defined in my header file along with that 'getData_Image' function.1-based indexing is for the matlab arrays as compared to C which is 0-based since I want to transfer pixel values to corresponding places. If all these are unclear, can you please let me know how to access each value of image (which is obviously a matrix) we read in matlab and pass to a C type multidimensional array.

This question is closed.

Tags

Asked:

on 2 Oct 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!