Hi all, I'm not sure if it is a bug, or whether I've just overlooked something obvious, but the internet did not offer much regarding this issue. I try to get slices from an image cube which consists of several images s = 1,...,n with the same dimensions. My new slice should have the width of the original images and the height of the number of images. Here is the code to do this: from skimage.io import ImageCollection, imsave from os.path import join import numpy as np def main(dir): ic = ImageCollection( join(dir, '*.png' ) ) row = 0 img = np.empty((len(ic), ic[0].shape[1], ic[0].shape[2] ) ) for s in range(len(ic)): img[s,...] = ic[s][row,...] # fname = 'new_{0:03d}.jpg'.format(v) # -> wrong colors fname = 'new_{0:03d}.png'.format(v) # -> output image is transparent imsave(fname, img) The problem is that the output images are all transparent. My input files are .png images with an alpha channel. I have also checked the values of the alpha channel of the output which are all set to 255, which, at least to my knowledge, should set the opacity to 100%. Regards, Marcel
Marcel, Would you be able to attach one of your images for me to test against? Regards, Steve On Wednesday, February 4, 2015 at 9:22:44 AM UTC-6, Marcel Gutsche wrote:
Hi all,
I'm not sure if it is a bug, or whether I've just overlooked something obvious, but the internet did not offer much regarding this issue. I try to get slices from an image cube which consists of several images s = 1,...,n with the same dimensions. My new slice should have the width of the original images and the height of the number of images. Here is the code to do this:
from skimage.io import ImageCollection, imsave
from os.path import join
import numpy as np
def main(dir):
ic = ImageCollection( join(dir, '*.png' ) )
row = 0
img = np.empty((len(ic), ic[0].shape[1], ic[0].shape[2] ) )
for s in range(len(ic)):
img[s,...] = ic[s][row,...]
# fname = 'new_{0:03d}.jpg'.format(v) # -> wrong colors
fname = 'new_{0:03d}.png'.format(v) # -> output image is transparent imsave(fname, img)
The problem is that the output images are all transparent. My input files are .png images with an alpha channel. I have also checked the values of the alpha channel of the output which are all set to 255, which, at least to my knowledge, should set the opacity to 100%.
Regards,
Marcel
Marcel, What about slicing out the alpha channel? Also, depending on memory considerations, you might try ic.concatenate(), which was my very first contribution to scikit-image! =D Juan. On Thu, Feb 5, 2015 at 2:22 AM, Marcel Gutsche <marcel.gutsche@gmail.com> wrote:
Hi all, I'm not sure if it is a bug, or whether I've just overlooked something obvious, but the internet did not offer much regarding this issue. I try to get slices from an image cube which consists of several images s = 1,...,n with the same dimensions. My new slice should have the width of the original images and the height of the number of images. Here is the code to do this: from skimage.io import ImageCollection, imsave from os.path import join import numpy as np def main(dir): ic = ImageCollection( join(dir, '*.png' ) ) row = 0 img = np.empty((len(ic), ic[0].shape[1], ic[0].shape[2] ) ) for s in range(len(ic)): img[s,...] = ic[s][row,...] # fname = 'new_{0:03d}.jpg'.format(v) # -> wrong colors fname = 'new_{0:03d}.png'.format(v) # -> output image is transparent imsave(fname, img) The problem is that the output images are all transparent. My input files are .png images with an alpha channel. I have also checked the values of the alpha channel of the output which are all set to 255, which, at least to my knowledge, should set the opacity to 100%. Regards, Marcel -- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Hi folks,
thanks for the quick reply. Removing the alpha channel worked. I also added one of my images as a reference for testing, why it does not work when alpha channels are provided. Also concatenate_images works well, thanks for the hint Juan. I haven't tested it for speed, but it is way more readable. One quick question to google-groups: Is it possible to answer using my email client? Marcel.
On Thu, Feb 5, 2015 at 1:20 AM, Marcel Gutsche <marcel.gutsche@gmail.com> wrote:
One quick question to google-groups: Is it possible to answer using my email client?
Yes, that is the way most of us do it, I think. You can adjust your mail delivery settings at https://groups.google.com/group/scikit-image Stéfan
Marcel, When you say the output image was transparent, you mean it was all white? I believe what happened is your call to `np.empty` creates a floating point array, which skimage expects to be in the range [0, 1], but your data is in the range [0, 255]. If you used `dtype=np.uint8` in your `np.empty` call, I suspect it would work. Regards, Steve On Wednesday, February 4, 2015 at 9:22:44 AM UTC-6, Marcel Gutsche wrote:
Hi all,
I'm not sure if it is a bug, or whether I've just overlooked something obvious, but the internet did not offer much regarding this issue. I try to get slices from an image cube which consists of several images s = 1,...,n with the same dimensions. My new slice should have the width of the original images and the height of the number of images. Here is the code to do this:
from skimage.io import ImageCollection, imsave
from os.path import join
import numpy as np
def main(dir):
ic = ImageCollection( join(dir, '*.png' ) )
row = 0
img = np.empty((len(ic), ic[0].shape[1], ic[0].shape[2] ) )
for s in range(len(ic)):
img[s,...] = ic[s][row,...]
# fname = 'new_{0:03d}.jpg'.format(v) # -> wrong colors
fname = 'new_{0:03d}.png'.format(v) # -> output image is transparent imsave(fname, img)
The problem is that the output images are all transparent. My input files are .png images with an alpha channel. I have also checked the values of the alpha channel of the output which are all set to 255, which, at least to my knowledge, should set the opacity to 100%.
Regards,
Marcel
Steve, that is a *great* catch!!! =D On Fri, Feb 6, 2015 at 1:19 PM, Steven Silvester <steven.silvester@gmail.com> wrote:
Marcel, When you say the output image was transparent, you mean it was all white? I believe what happened is your call to `np.empty` creates a floating point array, which skimage expects to be in the range [0, 1], but your data is in the range [0, 255]. If you used `dtype=np.uint8` in your `np.empty` call, I suspect it would work. Regards, Steve On Wednesday, February 4, 2015 at 9:22:44 AM UTC-6, Marcel Gutsche wrote:
Hi all,
I'm not sure if it is a bug, or whether I've just overlooked something obvious, but the internet did not offer much regarding this issue. I try to get slices from an image cube which consists of several images s = 1,...,n with the same dimensions. My new slice should have the width of the original images and the height of the number of images. Here is the code to do this:
from skimage.io import ImageCollection, imsave
from os.path import join
import numpy as np
def main(dir):
ic = ImageCollection( join(dir, '*.png' ) )
row = 0
img = np.empty((len(ic), ic[0].shape[1], ic[0].shape[2] ) )
for s in range(len(ic)):
img[s,...] = ic[s][row,...]
# fname = 'new_{0:03d}.jpg'.format(v) # -> wrong colors
fname = 'new_{0:03d}.png'.format(v) # -> output image is transparent imsave(fname, img)
The problem is that the output images are all transparent. My input files are .png images with an alpha channel. I have also checked the values of the alpha channel of the output which are all set to 255, which, at least to my knowledge, should set the opacity to 100%.
Regards,
Marcel
-- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Steve, the output image was really transparent, i.e. my image viewer showed a grey white checker pattern to indicate transparency. My actual implementation based on the Juan's hint regarding skimage.io.concatenate_images circumvents this issues by not creating an empty array in the first place, and by discarding the alpha channel. Regards, Marcel 2015-02-06 3:21 GMT+01:00 Juan Nunez-Iglesias <jni.soma@gmail.com>:
Steve, that is a *great* catch!!! =D
On Fri, Feb 6, 2015 at 1:19 PM, Steven Silvester < steven.silvester@gmail.com> wrote:
Marcel,
When you say the output image was transparent, you mean it was all white? I believe what happened is your call to `np.empty` creates a floating point array, which skimage expects to be in the range [0, 1], but your data is in the range [0, 255]. If you used `dtype=np.uint8` in your `np.empty` call, I suspect it would work.
Regards,
Steve
On Wednesday, February 4, 2015 at 9:22:44 AM UTC-6, Marcel Gutsche wrote:
Hi all,
I'm not sure if it is a bug, or whether I've just overlooked something obvious, but the internet did not offer much regarding this issue. I try to get slices from an image cube which consists of several images s = 1,...,n with the same dimensions. My new slice should have the width of the original images and the height of the number of images. Here is the code to do this:
from skimage.io import ImageCollection, imsave
from os.path import join
import numpy as np
def main(dir):
ic = ImageCollection( join(dir, '*.png' ) )
row = 0
img = np.empty((len(ic), ic[0].shape[1], ic[0].shape[2] ) )
for s in range(len(ic)):
img[s,...] = ic[s][row,...]
# fname = 'new_{0:03d}.jpg'.format(v) # -> wrong colors
fname = 'new_{0:03d}.png'.format(v) # -> output image is transparent imsave(fname, img)
The problem is that the output images are all transparent. My input files are .png images with an alpha channel. I have also checked the values of the alpha channel of the output which are all set to 255, which, at least to my knowledge, should set the opacity to 100%.
Regards,
Marcel
-- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
-- 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/_gmROuMT9uU/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.
participants (4)
-
Juan Nunez-Iglesias
-
Marcel Gutsche
-
Steven Silvester
-
Stéfan van der Walt