Skip to content

Conversation

@ThijsVroegh
Copy link
Contributor

This PR adds the option to the alignment page to visualize the feature point alignment between the base image and the aligned image. This is helpful because it allows to evaluate whether the feature based alignment is suited for the alignment of the data used.

@ThijsVroegh ThijsVroegh requested a review from stefsmeets August 16, 2024 08:45
Copy link
Contributor

@stefsmeets stefsmeets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, I left some comments in the code.

My main concern is that this is now the third different implementation of the 'detect and extract' pattern. We have src/unraphael/feature.py (skimage), src/unraphael/dash/align.py:feature_align (openCV) and now this function (skimage).

What is troubling me is that the alignment itself is using the OpenCV function, but that the display is using the skimage version without using the same parameters (e.g. the user can pick the max_ratio). And also, it uses the aligned images to find the feature points? This makes the visualization completely arbitrary, because it shows something completely different. I think the visualization should show the points and source images that are actually used in the alignment.

Comment on lines +474 to +475
def feature_based_alignment_visual(
base_image: np.ndarray,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest protecting this function by requiring keyword arguments:

Suggested change
def feature_based_alignment_visual(
base_image: np.ndarray,
def feature_based_alignment_visual(
*,
base_image: np.ndarray,

Comment on lines +502 to +506
Returns
-------
None
Displays a plot showing the feature-based alignment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary, but please update the function name/documentation that this will plot the aligment

Suggested change
Returns
-------
None
Displays a plot showing the feature-based alignment

Comment on lines +514 to +516
else:
st.error('Unsupported method selected.')
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider raising a ValueError instead of silently failing.

)

return res
return res, align_method, motion_model
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor this in a way that avoids returning a tuple? This makes the code difficult to maintain.

Comment on lines +272 to +282
display_in_grayscale = (
col2.radio('Display images in:', ['Grayscale', 'Original color)'])
== 'Grayscale'
)
# Slider to select max_ratio
max_ratio = col2.slider('Max ratio for descriptor matching', 0.5, 0.8, 0.6, 0.01)

st.write('')
st.write('')
st.subheader(f'Feature-based alignment visualization using {motion_model}')
st.write('')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be in the widget.

Comment on lines +620 to +623
with col1:
st.button('⏮️ Previous', on_click=previous_image)
with col3:
st.button('Next ⏭️', on_click=next_image)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have: sync these buttons with those from the comparison itself.

Comment on lines +611 to +615
def next_image():
st.session_state.image_index = (st.session_state.image_index + 1) % len(images)

def previous_image():
st.session_state.image_index = (st.session_state.image_index - 1) % len(images)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have: We use this pattern now in several places. Can we refactor/generalize it so that we avoid this code duplication everywhere?

Comment on lines +599 to +609
def display_current_image():
current_image = images[st.session_state.image_index]
feature_based_alignment_visual(
base_image=base_image.data,
target_image=current_image.data,
method=method,
base_image_name=base_image.name,
target_image_name=current_image.name,
display_in_grayscale=display_in_grayscale,
max_ratio=max_ratio,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be a function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants