-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Patches Visualization #628
Conversation
… into patches_visualization
@@ -1175,8 +1175,8 @@ def constrain_points_to_bounds(self, points): | |||
bounded_points[over_image] = shape[over_image] | |||
return bounded_points | |||
|
|||
def extract_patches(self, patch_centers, patch_size=(16, 16), | |||
sample_offsets=None, as_single_array=False): | |||
def extract_patches(self, patch_centers, patch_shape=(16, 16), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nooooo, why is this patch_shape
now? If we change patch_size
to patch_shape
then we need to do the same in menpofit!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True... However, I think we should be consistent on the naming of this argument. So we need to choose either patch_size
or patch_shape
(I prefer it) and use it everywhere. I will make a PR in menpofit that will add a widget for patch-based appearance models visualization. So the PR can also include renaming all patch_size
occurrences to patch_shape
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following our discussion with @patricksnape and @jabooth , it is agreed that we always use patch_shape
and we make it consistent throughout menpo and menpofit.
Just an update: menpo/menpofit#72 now defines the respective patch-based widgets in menpofit, so if you guys are happy, the two should be merged simultaneously. |
I guess we get this in and then split out the widgets? |
After discussing with @jabooth
Tell me you're happy. After this we'll split out the widgets (and visualize as well??) |
Just the widgets - visualize will stay because you can still view without a notebook. I'm happy with this and really need the |
for o in range(n_offsets): | ||
patches_array[p, o, ...] = patches_list[total_index].pixels | ||
total_index += 1 | ||
return patches_array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
underscore this name too, no point making it public API too early.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Just that one function to hide then we can get this in - +1 |
This PR adds functionality for visualizing a set of patches that are extracted from an image.
I. Patches representation
All the changes are made based on the assumption that patches are represented in one of the two formats that are returned by the
extract_patches()
method of Menpo'sImage
class, i.e.numpy.array
with shape(n_centers, n_offsets, n_channels, patch_height, patch_width)
list
ofn_centers * n_offsets
Image
objects, each of which has shape(n_channels, patch_height, patch_width)
where
n_centers
is the number of patches (points) andn_offsets
is the number of offsets per patch. Generally it is more efficient to use the first representation, that's why aconvert_patches_list_to_single_array(patches_list, n_centers)
method is defined inmenpo.image.base
. I also changed the default value ofas_single_array
toTrue
inextract_patches()
andextract_patches_around_landmarks()
methods.II. Set patches
In order to facilitate the patches visualization, I defined methods that are able to set patches to the correct locations of an image. Specifically,
set_patches()
method, similar to the existingextract_patches()
one.menpo.image.extract_patches.pyx
file, which is now renamed tomenpo.image.patches.pyx
.set_patches(patches, patch_centers, offset, offset_index)
andset_patches_around_landmarks(patches, group, label, offset, offset_index)
methods now exist in all image classes, i.e.Image
,MaskedImage
andBooleanImage
.offset
is a single offset value ((1, 2
numpy.array
orlist
ortuple
) that gets added topatch_centers
.offset_index
is the offset index value ofpatches
.build_mask_around_landmarks()
was different thanextract_patches()
andextract_patches_around_landmarks()
. Thanks to @patricksnape this is now made consistent.III. Visualize patches
A patches
numpy.array
orlist
can be visualized in two ways:III.A.
view_patches()
frommenpo.image
The basic arguments of this method are
patches
andpatch_centers
. The user can also pass in alist
with the patches indices to get visualized as well as select the patches offset. The method can optionally visualize the patches centers (PointCloud) as well as draw the bounding boxes around the patches. Finally, the background colour can optionally be either black or white.III.B.
visualize_patches()
widget frommenpo.visualize
The widget has a similar behaviour to the rest of the widgets. It includes options related to the channels and the renderer. However, it has an extra tab of options related to the patches. In there, the user can define the following:
::3
,:3
,1:10:2
,1, 2, 3
,[1, 2, 3]
,range(10)
,range(2, 10)
etc.IV. Example code
V. Open questions
There are still some open questions regarding the logic that I followed, for which I need your feedback:
PathBasedImage
class? (I have already discussed these with @patricksnape )view_patches()
method inmenpo.image
or should it be moved tomenpo.visualize
?menpofit
, for example the response maps of CLMs?