Comments (8)
Hi @gcapes,
There is a sentence related to this in episode 5 and I realize it should be moved to episode 3 instead, when using mode="L"
first appears. Sorry!
"The first argument to iio.imread() is the filename of the image. The second argument mode="L" defines the type and depth of a pixel in the image (e.g., an 8-bit pixel has a range of 0-255). This argument is forwarded to the pillow backend, for which mode āLā means 8-bit pixels and single-channel (i.e., grayscale). pillow is a Python imaging library; which backend is used by iio.imread() may be specified (to use pillow, you would pass this argument: plugin="pillow"); if unspecified, iio.imread() determines the backend to use based on the image type."
Do you have pillow
installed?
from image-processing.
Thanks for the quick reply !
I have now installed pillow
into my venv but that doesn't look to be the issue. mode="L"
doesn't look to be the problem either. If I remove that argument, I get a completely white image instead of completely black.
from image-processing.
Which OS are you running? Were you able to follow https://datacarpentry.org/image-processing/setup/? I guess the test at the end will give you a blank image at this point...
from image-processing.
I'm on Linux Mint. I'm not using Anaconda, but have set up a venv with all the required packages as far as I can tell, including scikit-image version 0.19.3 using python 3.10.
The test gives me what looks to be success:
I've worked round this problem it for the tutorial, so I'm only really reporting it as something which might affect other learners. It only seems to affect that png image. JPG and TIFF are loading ok.
Feel free to close if this isn't reproducible. Thanks!
from image-processing.
Strange... I cannot reproduce it on my end, indeed (the PNG image is displaying fine for me); I'm running Python 3.9.15 on Debian GNU/Linux 11 (bullseye).
from image-processing.
I can reproduce this.
(Aside: there is also a small error in the solution block, where we have forgotten to import imageio as iio
.)
The immediate issue is coming from the way that mode='L'
will return 8-bit integer values (rather than floating point intensities between 0 and 1 as produced by skimage.color.rgb2gray
):
The rest of the solution assumes that the image
array contains values between 0 and 1 but really they are between 0 and 255.
@gcapes here is a solution that should work for the exercise:
import imageio.v3 as iio
import matplotlib.pyplot as plt
image = iio.imread(uri="data/sudoku.png", mode="L")
image[image > 190] = 190
plt.imshow(image, cmap='gray', vmin=0, vmax=255)
Moving onto the question of how to fix this, it is made quite complicated by the fact that the sudoku image has an alpha channel. So skimage.color.rgb2gray
returns an error:
import skimage.color
image = iio.imread(uri="data/sudoku.png")
gray_image = skimage.color.rgb2gray(image)
ValueError: the input array must have size 3 along `channel_axis`, got (900, 900, 4)
I can propose four options from here:
- We find a way to load the image as floating point intensity values
- We adjust the rest of the exercise to work with 8-bit integer values, and highlight the difference between the outputs of
skimage.color.rgb2gray
andiio.imread(mode='L')
in the Converting colour images to grayscale section above the exercise. - We adopt the
skimage.color.rgb2gray
approach to solve this exercise, and talk through the existence of the alpha channel and how to deal with it. - We remove the alpha channel from the image, and provide a three-channel version as the example file in the
data
folder, then use thergb2gray
approach.
Here are my thoughts on each of these:
- I do not know if this is possible. A quick review of the Pillow documentation did not seem to show me a mode we could use to achieve it.
- We should add the note about the different outputs to the Converting colour images to grayscale section.
- I would really prefer to avoid a discussion of alpha channels at this stage of the lesson, and the middle of an exercise is definitely not the right place for it regardless.
- This would be easy enough to do, even if it does mean creating a new version of the dataset on FigShare. But I wonder if really we want to be recommending
mode='L'
overrgb2gray
in general.
Thoughts very welcome from anyone with more working experience of image processing @mkcor @bobturneruk @K-Meech @quist00 @uschille
from image-processing.
Well done @tobyhodges for getting to the bottom of this!
I would suggest option 4. It requires the least extra explaining and keeps to the learning objectives.
from image-processing.
Oh, sorry, I had skipped the vmin=0, vmax=1
arguments in the plotting function... Mystery solved.
I agree that using a conversion function such as rgb2gray
is a more robust practice and it is more transparent to the learner.
from image-processing.
Related Issues (20)
- Ep3: Image not writeable HOT 6
- Ep3: Wrong file name `data/sudoku.jpg` HOT 5
- Convert sudoku.png image to pure RGB (without alpha channel) HOT 9
- Release new version of image dataset on FigShare HOT 2
- Use `uint8` or `float64` for grayscale images? HOT 1
- Using image as a variable name HOT 7
- Carpentries Workbench Transition HOT 22
- Showcase image processing at AUNZ community call HOT 7
- Links need to be fixed in CONTRIBUTING.md
- latest version of lesson using "import imageio.v3 as iio" causes error HOT 4
- 'code' folder should be re-established/replaced HOT 5
- Code snippet docstring formatting HOT 4
- Transition to new import convention for sckit-image? HOT 4
- Contributing guide should be customised further
- Ep 5 - Using a Mask for a Histogram exercise error in solution HOT 3
- Link to image publication & analysis checklists HOT 2
- Mask in episode 4 has no shadow HOT 1
- Matplotlib is currently used in a hybrid way (explicit vs. implicit interfaces) HOT 4
- Add Exiftool in list of software that can help handle metadata
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from image-processing.