refactoring: renamed width() into get_width() to avoid confusion with properties

This commit is contained in:
Guillaume Raffy 2020-02-13 14:34:32 +01:00
parent 777db445be
commit df1a9b869f
5 changed files with 18 additions and 18 deletions

View File

@ -47,11 +47,11 @@ class IImage(ABC):
pass
@abc.abstractmethod
def width(self):
def get_width(self):
pass
@abc.abstractmethod
def height(self):
def get_height(self):
pass
@abc.abstractmethod
@ -93,11 +93,11 @@ class IImage(ABC):
class IHyperStack(ABC):
@abc.abstractmethod
def width(self):
def get_width(self):
pass
@abc.abstractmethod
def height(self):
def get_height(self):
pass
@abc.abstractmethod
@ -160,7 +160,7 @@ class IImageFeeder(ABC):
image = it.next()
ie = IImageEngine.get_instance()
hyperstack = ie.create_hyperstack(width=image.width(), height=image.height(), num_channels=1, num_slices=1, num_frames=self.get_num_images(), pixel_type=image.get_pixel_type())
hyperstack = ie.create_hyperstack(width=image.get_width(), height=image.get_height(), num_channels=1, num_slices=1, num_frames=self.get_num_images(), pixel_type=image.get_pixel_type())
frame_index = 0
for image in it:
hyperstack.set_image(image, frame_index=frame_index)

View File

@ -46,7 +46,7 @@ class IJImage(IImage):
def clone(self, clone_pixel_type=None):
if clone_pixel_type == None:
clone_pixel_type = self.get_pixel_type()
copy = IJImage(self.image_engine, width=self.width(), height=self.height(), pixel_type=clone_pixel_type)
copy = IJImage(self.image_engine, width=self.get_width(), height=self.get_height(), pixel_type=clone_pixel_type)
src_processor = self.ij_image.getProcessor()
clone_processor = {
PixelType.U8: src_processor.convertToByteProcessor(),
@ -57,10 +57,10 @@ class IJImage(IImage):
assert copy.get_pixel_type() == clone_pixel_type
return copy
def width(self):
def get_width(self):
return self.ij_image.width
def height(self):
def get_height(self):
return self.ij_image.height
def get_pixel_type(self):
@ -113,15 +113,15 @@ class IJHyperStack(IHyperStack):
def get_image(self, frame_index=0, slice_index=0, channel_index=0):
self.hyperstack.setPositionWithoutUpdate(channel_index + 1, slice_index + 1, frame_index + 1)
stack_name = ''
image_plus = IJ.createHyperStack(stack_name, self.width(), self.height(), 1, 1, 1, PixelType.get_num_bits(self.get_pixel_type()))
image_plus = IJ.createHyperStack(stack_name, self.get_width(), self.get_height(), 1, 1, 1, PixelType.get_num_bits(self.get_pixel_type()))
image_plus.setProcessor(self.hyperstack.getProcessor())
ij_image = IJImage(self.image_engine, image_plus)
return ij_image
def width(self):
def get_width(self):
return self.hyperstack.width
def height(self):
def get_height(self):
return self.hyperstack.height
def num_slices(self):
@ -334,7 +334,7 @@ class IJImageEngine(IImageEngine):
imp2mat = ImagePlusMatConverter()
cv_src_image = imp2mat.toMat(src_image.ij_image.getProcessor())
cv_template_image = imp2mat.toMat(template_image.ij_image.getProcessor())
similarity_image_size = opencv_core.Size(src_image.width()-template_image.width()+1, src_image.width()-template_image.height()+1)
similarity_image_size = opencv_core.Size(src_image.get_width()-template_image.get_width()+1, src_image.get_width()-template_image.get_height()+1)
cv_similarity_image = opencv_core.Mat(similarity_image_size, cv_src_image.type())
# warning ! trying to guess the arguments from opencv's documentation is time consuming as the error messages are misleading (in the following call, javacpp complains that the 1st argument is not a org.bytedeco.javacpp.opencv_core$Mat, while it is ! The problem comes from the order of the arguments). So, instead of guessing, the found accepted signatures of cvMatchTemplate are in https://github.com/bytedeco/javacpp-presets/blob/master/opencv/src/gen/java/org/bytedeco/opencv/global/opencv_imgproc.java
@ -363,8 +363,8 @@ class IJImageEngine(IImageEngine):
# print(cv_similarity_image)
similarity_image = self.create_image(
width=src_image.width()-template_image.width()+1,
height=src_image.height()-template_image.height()+1,
width=src_image.get_width()-template_image.get_width()+1,
height=src_image.get_height()-template_image.get_height()+1,
pixel_type=PixelType.F32)
mat2imp = MatImagePlusConverter()

View File

@ -178,7 +178,7 @@ def correct_non_uniform_lighting(non_uniform_sequence, channel_id, white_estimat
ie = IImageEngine.get_instance()
white_estimate = white_estimator.estimate_white([non_uniform_sequence], [channel_id])
uniform_stack = ie.create_hyperstack(width=white_estimate.width(), height=white_estimate.height(), num_slices=1, num_frames=non_uniform_sequence.num_frames, num_channels=1, pixel_type=PixelType.F32)
uniform_stack = ie.create_hyperstack(width=white_estimate.get_width(), height=white_estimate.get_height(), num_slices=1, num_frames=non_uniform_sequence.num_frames, num_channels=1, pixel_type=PixelType.F32)
for frame_index in range(non_uniform_sequence.num_frames):
non_uniform_frame = ie.load_image(non_uniform_sequence.get_image_file_path(channel_index=0, frame_index=frame_index, slice_index=0))
@ -221,7 +221,7 @@ def correct_non_uniform_lighting(non_uniform_sequence, channel_id, white_estimat
# :return IHyperStack: the hyperstack of images after correction
# """
# white_estimate = white_estimator.estimate_white([non_uniform_sequence], [channel_id])
# uniform_stack = IImageEngine.get_instance().create_hyperstack(width=white_estimate.width(), height=white_estimate.height(), num_slices=1, num_frames=non_uniform_sequence.num_frames, num_channels=1, pixel_type=PixelType.F32)
# uniform_stack = IImageEngine.get_instance().create_hyperstack(width=white_estimate.get_width(), height=white_estimate.get_height(), num_slices=1, num_frames=non_uniform_sequence.num_frames, num_channels=1, pixel_type=PixelType.F32)
# for frame_index in range(non_uniform_sequence.num_frames):
# non_uniform_frame = IImageEngine.get_instance().load_image(non_uniform_sequence.get_image_file_path(channel_index=0, frame_index=frame_index, slice_index=0))

View File

@ -107,7 +107,7 @@ class TrapsDetector(object):
binarizer = TrapBinarizer((70,34))
trap_mask = binarizer.binarize_trap(clean_trap_image)
traps_mask = ie.create_image(width=uniform_stack.width(), height=uniform_stack.height(), pixel_type=uniform_stack.get_pixel_type())
traps_mask = ie.create_image(width=uniform_stack.get_width(), height=uniform_stack.get_height(), pixel_type=uniform_stack.get_pixel_type())
for frame_trap_index in range(num_traps_per_frame):
match = matches[frame_trap_index]
traps_mask.set_subimage(trap_mask, (match.x, match.y))

View File

@ -56,7 +56,7 @@ class TestLipase(unittest.TestCase):
template_trap_aabb = Aabb(x_min, y_min, x_max, y_max)
template_trap_image = first_image.get_subimage(template_trap_aabb)
for image in [first_image, template_trap_image]:
print(image.get_pixel_type(), image.width(), image.height())
print(image.get_pixel_type(), image.get_width(), image.get_height())
# the typical value of peaks is -2.e10 and the value between peaks is below -8.0e10
threshold = -3.0e10
tolerance = 1.0e10