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

Ep3: Image not writeable #247

Closed
gcapes opened this issue Feb 8, 2023 · 6 comments · Fixed by #253
Closed

Ep3: Image not writeable #247

gcapes opened this issue Feb 8, 2023 · 6 comments · Fixed by #253
Assignees
Labels
status:in progress Contributor working on issue status:need more info More information needed type:discussion Discussion or feedback about the lesson

Comments

@gcapes
Copy link

gcapes commented Feb 8, 2023

In this section https://datacarpentry.org/image-processing/03-skimage-images/index.html#manipulating-pixels we're keeping only high-intensity pixels. However, I get the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[34], line 2
      1 # keep only high-intensity pixels
----> 2 image[image < 128] = 0
      4 # display modified image
      5 fig, ax = plt.subplots()

ValueError: assignment destination is read-only

Making a copy of the image first fixes the problem. image_copy = image.copy()

@tobyhodges
Copy link
Member

Thanks for reporting this and the other issues, @gcapes - you are finding wrinkles that it is very helpful to iron out!

That said, I'm afraid I have not been able to reproduce this one.

editing image object

Could you share the whole code block and output please, so we can try to figure out what is going on here?

@gcapes
Copy link
Author

gcapes commented Feb 9, 2023

MWE:

import numpy as np
import matplotlib.pyplot as plt
import ipympl
import imageio.v3 as iio
import skimage
%matplotlib widget

"""
* Python script to ignore low intensity pixels in an image.
*
"""
import imageio.v3 as iio

# read input image
image = iio.imread(uri="data/maize-root-cluster.jpg")

# display original image
fig, ax = plt.subplots()
plt.imshow(image)

image

# keep only high-intensity pixels
image[image < 128] = 0

# display modified image
fig, ax = plt.subplots()
plt.imshow(image)

image

@tobyhodges
Copy link
Member

Hmmm. Can confirm this works with no errors on my end. I will go looking for an explanation of why this might be happening to you elsewhere on the Internet...

@tobyhodges
Copy link
Member

Ok, I believe this issue thread provides an explanation for the behaviour you're observing: imageio/imageio#877

I need to spend some time reading through it, and then I think it will need to be raised with the rest of the Maintainer team, and potentially the Curriculum Advisors, to figure out how we will handle this consistently throughout the lesson.

@tobyhodges tobyhodges added status:need more info More information needed type:discussion Discussion or feedback about the lesson labels Feb 9, 2023
@uschille uschille self-assigned this Mar 11, 2023
@uschille
Copy link
Contributor

I can reproduce this. Will dig into it while addressing #252.

@uschille
Copy link
Contributor

Based on the discussions in imageio/imageio#877 and python-pillow/Pillow#6581, image = np.array(image) may be a quick fix. A downside of this is the added cognitive load of thinking about writeable/non-writeable images. Maybe this is unavoidable in view of how the imageio backend works.

@mkcor Do you have any better suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:in progress Contributor working on issue status:need more info More information needed type:discussion Discussion or feedback about the lesson
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants