def _extract_image(self, raw_image):
ncomps = raw_image.contents.numcomps<EOL>dtypes, nrows, ncols = [], [], []<EOL>for k in range(raw_image.contents.numcomps):<EOL><INDENT>component = raw_image.contents.comps[k]<EOL>dtypes.append(self._component2dtype(component))<EOL>nrows.append(component.h)<EOL>ncols.append(component.w)<EOL><DEDENT>is_cube = all(r == nrows[<NUM_LIT:0>] and c == ncols[<NUM_LIT:0>] and d == dtypes[<NUM_LIT:0>]<EOL>for r, c, d in zip(nrows, ncols, dtypes))<EOL>if is_cube:<EOL><INDENT>image = np.zeros((nrows[<NUM_LIT:0>], ncols[<NUM_LIT:0>], ncomps), dtypes[<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>image = []<EOL><DEDENT>for k in range(raw_image.contents.numcomps):<EOL><INDENT>component = raw_image.contents.comps[k]<EOL>self._validate_nonzero_image_size(nrows[k], ncols[k], k)<EOL>addr = ctypes.addressof(component.data.contents)<EOL>with warnings.catch_warnings():<EOL><INDENT>warnings.simplefilter("<STR_LIT:ignore>")<EOL>nelts = nrows[k] * ncols[k]<EOL>band = np.ctypeslib.as_array(<EOL>(ctypes.c_int32 * nelts).from_address(addr))<EOL>if is_cube:<EOL><INDENT>image[:, :, k] = np.reshape(band.astype(dtypes[k]),<EOL>(nrows[k], ncols[k]))<EOL><DEDENT>else:<EOL><INDENT>image.append(np.reshape(band.astype(dtypes[k]),<EOL>(nrows[k], ncols[k])))<EOL><DEDENT><DEDENT><DEDENT>if is_cube and image.shape[<NUM_LIT:2>] == <NUM_LIT:1>:<EOL><INDENT>image.shape = image.shape[<NUM_LIT:0>:<NUM_LIT:2>]<EOL><DEDENT>return image<EOL>
Extract unequally-sized image bands.

Parameters
----------
raw_image : reference to openjpeg ImageType instance
    The image structure initialized with image characteristics.

Returns
-------
list or ndarray
    If the JPEG 2000 image has unequally-sized components, they are
    extracted into a list, otherwise a numpy array.