Open Dr-QTDS opened 2 months ago
Hello, the problem seems to be happening because of the slicing (np_data[:, 0:300]
), which apparently gets lost when passed through the library. In fact, calling converter.CopyBlock(np_data, block_index)
for both blocks produces the same result. While this looks like a bug to me as well, allocating arrays larger than a block sort of defeats its purpose. The following produces the expected result (note the block_size
instead of image_size
):
np_data = np.zeros((block_size.y, block_size.x), dtype=configuration.mNp_type)
[...]
if x == 0:
np_data[:, 0:100] = 50
np_data[:, 100:200] = 0
np_data[:, 200:300] = 150
else:
np_data[:, 0:100] = 0
np_data[:, 100:200] = 250
np_data[:, 200:300] = 0
converter.CopyBlock(np_data, block_index)
Mismatching the declared types produces the expected pattern because a non-sliced numpy array of the file type is created by copying the given numpy sliced array data (the library makes sure that an array of the right type is passed to the library, even if creating a temporary copy might be expensive in terms of time and memory).
Hope this helps.
I am using Windows 10 to convert images. I have tested the
testPy/PyImarisWriterExample.py
code and it ran correctly. I edited the code as below:I edited the
image_size
in line 57,block_size
in line 59, changed values between lines 69 and 71, and edited lines between 94 and 97 to test how to paste a small image to a big canvas. Though the code can run successfully, the output image is incorrect. The output image looks like the below picture.But if I edit the
configurations.append(TestConfiguration(len(configurations), 'uint8 image from uint8 numpy array', np.uint8, 'uint8', [PW.Color(0.086, 0.608, 0.384, 1), PW.Color(1, 1, 1, 1), PW.Color(1, 0.533, 0.243, 1)]))
toconfigurations.append(TestConfiguration(len(configurations), 'uint8 image from uint8 numpy array', np.uint8, 'uint16', [PW.Color(0.086, 0.608, 0.384, 1), PW.Color(1, 1, 1, 1), PW.Color(1, 0.533, 0.243, 1)]))
, I just changed'uint8'
to'uint16'
, the output image shows correctly as below.But as in the above code, the dtype of the NumPy array is
uint8
. So is this a bug or is something wrong in my code. Please help me, thanks!