Re: [Imtoolkit-users] segmentation fault by inFileReadImageData
Brought to you by:
scuri
From: phool p. <pho...@gm...> - 2010-05-31 05:38:38
|
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? |