Re: [Imtoolkit-users] segmentation fault by inFileReadImageData
Brought to you by:
scuri
From: Antonio S. <sc...@te...> - 2010-05-31 18:14:10
|
"depth" is the number of planes the image has, GRAY images have depth=1, RGB depth=3, RGB with alpha depth=4. The function imColorModeDepth will compute the depth from the color_mode for you. "d" is the current plane you are processing, similar to x and y. The code you sent, seems to be correct, considering the function r_matrix(m, n) does the necessary type convertion. What's the result? BTW, if you are using C++ the processing of several data types is easier if you use templates. Inside the IM source code you will see several functions using templates internally. Even though their API is in C. BTW2, I noticed that you are storing separated planes (not packed). You can configure imFileReadImageData to load unpacked data even if the data in the file is packed. Best, scuri From: phool preet [mailto:pho...@gm...] Sent: segunda-feira, 31 de maio de 2010 02:38 To: imt...@li... Subject: Re: [Imtoolkit-users] segmentation fault by inFileReadImageData hello all... these are some lines from online user guide...... ---------------------------------------------------------------------------- --------------------------------------------------------------------------- To create a raw image buffer you can simply use the utility function: int width, height, color_mode, data_type; int size = imImageDataSize(width, height, color_mode, data_type); void* buffer = malloc(size); So if the data type is IM_FLOAT, we could write: float* idata = (float*)buffer; Then to locate the pixel at line y, column x, component d simply write: float value; if (is_packed) value = idata[y*width*depth + x*depth + d] else value = idata[d*width*height + y*width + x] ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- what are the parameters d and depth are? i am trying to read RGB values from image data. i have written a code but that doesn't seems to be working..... if (imColorModeSpace(color_mode) == IM_RGB && imColorModeIsPacked(color_mode)) { switch (data_type) { case IM_BYTE : { std::cout << "IM_BYTE\n"; unsigned char *ptr_to_uchar = (unsigned char *)data; for (int m = 1; m <= height; m++) { for (int n = 1; n <= width; n++) { r_matrix(m, n) = *ptr_to_uchar++; g_matrix(m, n) = *ptr_to_uchar++; b_matrix(m, n) = *ptr_to_uchar++; } } break; } case IM_USHORT : { std::cout << "IM_USHORT\n"; unsigned short *ptr_to_ushort = (unsigned short *)data; for (int m = 1; m <= height; m++) { for (int n = 1; n <= width; n++) { //std::cout << m << " " << n << '\n'; r_matrix(m, n) = *ptr_to_ushort++; g_matrix(m, n) = *ptr_to_ushort++; b_matrix(m, n) = *ptr_to_ushort++; } } break; } case IM_INT : { std::cout << "IM_INT\n"; int *ptr_to_int = (int *)data; for (int m = 1; m <= height; m++) { for (int n = 1; n <= width; n++) { //std::cout << m << " " << n << '\n'; r_matrix(m, n) = *ptr_to_int++; g_matrix(m, n) = *ptr_to_int++; b_matrix(m, n) = *ptr_to_int++; } } break; } case IM_FLOAT : { std::cout << "IM_FLOAT\n"; float *ptr_to_float = (float *)data; for (int m = 1; m <= height; m++) { for (int n = 1; n <= width; n++) { //std::cout << m << " " << n << '\n'; r_matrix(m, n) = *ptr_to_float++; g_matrix(m, n) = *ptr_to_float++; b_matrix(m, n) = *ptr_to_float++; } } break; } default : std::cout << "Unrecognized or unsupported Data Type\n"; break; } can anybody tell what i am missing? |