Skip to content
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

Connected components suggestions #316

Merged

Conversation

JeremyPike
Copy link
Contributor

@JeremyPike JeremyPike commented Dec 13, 2023

Suggestions and minor corrections for connected components episode. The most notable change is in the "Color mappings spoiler" where it looks like the default behaviour of matplotlib.pyplot.imshow has changed since the section was written such the data range for display is now automatically adjusted to the range of the image. The default colour map is also not grayscale so a empty image will appear blue not black I've modified the text to reflect these changes and also highlighted what vmin and vmax do which is very useful here.

Copy link

github-actions bot commented Dec 13, 2023

Thank you!

Thank you for your pull request 😃

🤖 This automated message can help you check the rendered files in your submission for clarity. If you have any questions, please feel free to open an issue in {sandpaper}.

If you have files that automatically render output (e.g. R Markdown), then you should check for the following:

  • 🎯 correct output
  • 🖼️ correct figures
  • ❓ new warnings
  • ‼️ new errors

Rendered Changes

🔍 Inspect the changes: https://github.com/datacarpentry/image-processing/compare/md-outputs..md-outputs-PR-316

The following changes were observed in the rendered markdown documents:

 08-connected-components.md | 53 ++++++++++++++++++++++++++--------------------
 md5sum.txt                 |  2 +-
 2 files changed, 31 insertions(+), 24 deletions(-)
What does this mean?

If you have source files that require output and figures to be generated (e.g. R Markdown), then it is important to make sure the generated figures and output are reproducible.

This output provides a way for you to inspect the output in a diff-friendly manner so that it's easy to see the changes that occur due to new software versions or randomisation.

⏱️ Updated at 2023-12-15 15:30:27 +0000

github-actions bot pushed a commit that referenced this pull request Dec 13, 2023
@JeremyPike JeremyPike marked this pull request as ready for review December 13, 2023 07:02
github-actions bot pushed a commit that referenced this pull request Dec 13, 2023
Copy link
Member

@tobyhodges tobyhodges left a comment

Choose a reason for hiding this comment

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

I've suggested modifying the title of the spoiler box, but in general this is excellent. Thanks @JeremyPike 🙌

Co-authored-by: Toby Hodges <[email protected]>
@JeremyPike
Copy link
Contributor Author

@tobyhodges yes that's a better header, change made :)

github-actions bot pushed a commit that referenced this pull request Dec 15, 2023
@tobyhodges tobyhodges merged commit 42bb13a into datacarpentry:main Dec 15, 2023
3 checks passed
github-actions bot pushed a commit that referenced this pull request Dec 15, 2023
Auto-generated via {sandpaper}
Source  : 42bb13a
Branch  : main
Author  : Toby Hodges <[email protected]>
Time    : 2023-12-15 16:11:10 +0000
Message : Merge pull request #316 from bear-rsg/connected-components-suggestions

Connected components suggestions
github-actions bot pushed a commit that referenced this pull request Dec 15, 2023
Auto-generated via {sandpaper}
Source  : c3b0ad5
Branch  : md-outputs
Author  : GitHub Actions <[email protected]>
Time    : 2023-12-15 16:12:08 +0000
Message : markdown source builds

Auto-generated via {sandpaper}
Source  : 42bb13a
Branch  : main
Author  : Toby Hodges <[email protected]>
Time    : 2023-12-15 16:11:10 +0000
Message : Merge pull request #316 from bear-rsg/connected-components-suggestions

Connected components suggestions
@@ -316,24 +316,22 @@ labeled_image, count = connected_components(filename="data/shapes-01.jpg", sigma

fig, ax = plt.subplots()
plt.imshow(labeled_image)
plt.axis("off");
plt.axis("off")
Copy link
Contributor

Choose a reason for hiding this comment

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

I would keep the semicolon, so the output is not cluttered with text and memory addresses... But maybe the semicolon should be explained to learners? cf. mkcor/python-prog#8 (comment) 😉

Copy link
Contributor Author

@JeremyPike JeremyPike Dec 18, 2023

Choose a reason for hiding this comment

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

Sure, sorry, I probably shouldn't have removed this! I don't use Jupyter much apart from for teaching so from my perspective I thought it might be confusing for some participants and I didn't mind seeing the limits of the axis printed. Happy to put back in with a brief explanation :)


Here you might get a warning
If you are using an old version of Matplotlib you might get a warning
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If you are using an old version of Matplotlib you might get a warning
If you are using an older version of Matplotlib you might get a warning

Comment on lines +364 to +365
fig, ax = plt.subplots()
plt.imshow(labeled_image, vmin=np.min(labeled_image), vmax=np.max(labeled_image))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fig, ax = plt.subplots()
plt.imshow(labeled_image, vmin=np.min(labeled_image), vmax=np.max(labeled_image))
plt.imshow(labeled_image, vmin=np.min(labeled_image), vmax=np.max(labeled_image))

Since fig and ax are not being used?

Copy link
Contributor Author

@JeremyPike JeremyPike Dec 18, 2023

Choose a reason for hiding this comment

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

fig, ax = plt.subplots() is used here as I wanted to create a new figure rather than use the previous one, its used throughout the course even when fig and ax are not used so I'm hesitant to change to an alternative or remove the line. Maybe I don't need to create a new figure though, in which case the line can be removed as suggested?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, ok, thanks for explaining! So, I would suggest you keep this line but replace the next one with:

ax.imshow(labeled_image, vmin=np.min(labeled_image), vmax=np.max(labeled_image))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree this is better but its not consistent with how its done in the rest of the course so perhaps this should be a different PR where all similar examples are changed at once.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree; I believe that we should use this "object-oriented (OO) style" throughout the lesson, since we create figure and axis objects now. At the moment, we are mixing up the OO-style with the pyplot-style [1]. For instance, 328d544 adds figure and axis objects, but we still have all the pyplot-style legacy. I would change, e.g.,

fig, ax = plt.subplots()
plt.plot(bin_edges[0:-1], histogram)
plt.title("Grayscale Histogram")
plt.xlabel("grayscale value")
plt.ylabel("pixels")
plt.xlim(0, 1.0)

into

fig, ax = plt.subplots()
ax.plot(bin_edges[0:-1], histogram)
ax.set_title("Grayscale Histogram")
ax.set_xlabel("grayscale value")
ax.set_ylabel("pixels")
ax.set_xlim(0, 1.0);

/cc @datacarpentry/image-processing-curriculum-maintainers

[1] https://matplotlib.org/stable/users/explain/quick_start.html#the-explicit-and-the-implicit-interfaces

Copy link
Member

Choose a reason for hiding this comment

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

Good catch, @mkcor. Please could you open a new issue where we can track this?

@@ -380,7 +385,7 @@ colored_label_image = ski.color.label2rgb(labeled_image, bg_label=0)

fig, ax = plt.subplots()
plt.imshow(colored_label_image)
plt.axis("off");
plt.axis("off")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.

@@ -402,7 +407,7 @@ How does changing the `sigma` and `threshold` values influence the result?
## Solution

As you might have guessed, the return value `count` already
contains the number of found images. So it can simply be printed
contains the number of found objects in the image. So it can simply be printed
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
contains the number of found objects in the image. So it can simply be printed
contains the number of objects found in the image. So it can simply be printed

@JeremyPike
Copy link
Contributor Author

JeremyPike commented Dec 18, 2023

@mkcor thanks for the nice review and great suggestions (see my comments above). However I think @tobyhodges has already merged this and I cant see an easy way to reopen. I'm happy to create a new PR with the changes if thats the best way?

@mkcor
Copy link
Contributor

mkcor commented Dec 18, 2023

I'm happy to create a new PR with the changes if thats the best way?

You're most welcome, @JeremyPike! Yes, I think that creating a new PR would be the way to go. Thank you!

@JeremyPike JeremyPike mentioned this pull request Dec 18, 2023
@JeremyPike
Copy link
Contributor Author

I'm happy to create a new PR with the changes if thats the best way?

You're most welcome, @JeremyPike! Yes, I think that creating a new PR would be the way to go. Thank you!

Done, see #318

github-actions bot pushed a commit that referenced this pull request Dec 19, 2023
Auto-generated via {sandpaper}
Source  : c3b0ad5
Branch  : md-outputs
Author  : GitHub Actions <[email protected]>
Time    : 2023-12-15 16:12:08 +0000
Message : markdown source builds

Auto-generated via {sandpaper}
Source  : 42bb13a
Branch  : main
Author  : Toby Hodges <[email protected]>
Time    : 2023-12-15 16:11:10 +0000
Message : Merge pull request #316 from bear-rsg/connected-components-suggestions

Connected components suggestions
@JeremyPike JeremyPike deleted the connected-components-suggestions branch February 2, 2024 10:23
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