The right way to access red channel in Lena
I'm trying to build a filter to show only the red channel in the lena image. I defined two masks: (1,0,0) (255,0,0) Oddly, the (255,0,0) gives me the correct plot when doing imshow(), but (1,0,0) doesn't. Why does the (1,0,0) mask lead to light regions being dark and dark regions being light? Here's a working example: %pylab inline from skimage.data import lena lena = lena() f, (ax1, ax2) = plt.subplots(1,2, figsize=(8,6)) ax1.imshow(lena*(1,0,0)) ax2.imshow(lena*(255,0,0))
Hi Adam, You can slice out just the red channel with `lena[..., 0]`, which is equivalent to `lena[:, :, 0]`. The result will be a rank 2 array representing the red channel. This ability is made possible by NumPy.
I don't think the image came through. Let me attach it On Thursday, March 26, 2015 at 7:16:12 PM UTC-4, Adam Hughes wrote:
I'm trying to build a filter to show only the red channel in the lena image. I defined two masks:
(1,0,0) (255,0,0)
Oddly, the (255,0,0) gives me the correct plot when doing imshow(), but (1,0,0) doesn't. Why does the (1,0,0) mask lead to light regions being dark and dark regions being light? Here's a working example:
%pylab inline from skimage.data import lena
lena = lena()
f, (ax1, ax2) = plt.subplots(1,2, figsize=(8,6))
ax1.imshow(lena*(1,0,0)) ax2.imshow(lena*(255,0,0))
Thanks Josh. I actually would normally do it that way, but I stumbled on this behavior when we were trying to build filters. For example, scale the red channel by 50% via multiplying by (0.5, 1, 1). Just curious what's going on, and why multiplcation by (1,0,0) doesn't work. On Thu, Mar 26, 2015 at 7:31 PM, Adam Hughes <hughesadam87@gmail.com> wrote:
I don't think the image came through. Let me attach it
On Thursday, March 26, 2015 at 7:16:12 PM UTC-4, Adam Hughes wrote:
I'm trying to build a filter to show only the red channel in the lena image. I defined two masks:
(1,0,0) (255,0,0)
Oddly, the (255,0,0) gives me the correct plot when doing imshow(), but (1,0,0) doesn't. Why does the (1,0,0) mask lead to light regions being dark and dark regions being light? Here's a working example:
%pylab inline from skimage.data import lena
lena = lena()
f, (ax1, ax2) = plt.subplots(1,2, figsize=(8,6))
ax1.imshow(lena*(1,0,0)) ax2.imshow(lena*(255,0,0))
--
You received this message because you are subscribed to a topic in the Google Groups "scikit-image" group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/scikit-image/JzmfEbBJKYU/unsubscribe. To unsubscribe from this group and all its topics, send an email to scikit-image+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Hi Adam On Thu, Mar 26, 2015 at 4:31 PM, Adam Hughes <hughesadam87@gmail.com> wrote:
ax1.imshow(lena*(1,0,0)) ax2.imshow(lena*(255,0,0))
The multiplication turns your image's dtype into uint64, which causes the scaling problems. I prefer with float images, always ensuring that they are in [0, 1] and then specifying vmin=0 and vmax=1 to matplotlib. Regards Stéfan
participants (3)
-
Adam Hughes -
Josh Warner -
Stéfan van der Walt