Hi Michael, You can use the `.values` property to get a NumPy array out of a pandas DataFrame. After that it’s just a matter of slight reshaping to make skimage think that it’s a long, thin image. =)
======================================== In [1]: x = np.array([[0, 0, 255], [55, 0, 25], [4, 0, 5]]).astype(np.uint8) In [2]: from skimage import img_as_float, color In [12]: x = img_as_float(x) In [15]: df = pd.DataFrame(dict(RGB_r=x[:, 0], RGB_g=x[:, 1], RGB_b=x[:, 2])) In [16]: df[['RGB_r', 'RGB_g', 'RGB_b']].values Out[16]: array([[ 0. , 0. , 1. ], [ 0.21568627, 0. , 0.09803922], [ 0.01568627, 0. , 0.01960784]]) In [17]: lab = color.rgb2lab(df[['RGB_r', 'RGB_g’, 'RGB_b']].values[np.newaxis])[0] In [18]: lab Out[18]: array([[ 32.29567257, 79.18559091, -107.85730021], [ 7.97293614, 28.7263062 , -0.51735934], [ 0.33216914, 1.74121634, -1.52356365]]) In [19]: df['Lab_l'], df['Lab_a'], df['Lab_b'] = lab.T In [20]: df Out[20]: RGB_b RGB_g RGB_r Lab_l Lab_a Lab_b 0 1.000000 0.0 0.000000 32.295673 79.185591 -107.857300 1 0.098039 0.0 0.215686 7.972936 28.726306 -0.517359 2 0.019608 0.0 0.015686 0.332169 1.741216 -1.523564 ======================================== Just make sure your RGB values are in the right data type and range for scikit-image: http://scikit-image.org/docs/dev/user_guide/data_types.html Typically that means uint8s in [0, 255] or floats in [0, 1]. Hope this helps! Juan. On 4 Mar 2017, 1:44 AM +1100, Michael O'Brien <mob....@gmail.com>, wrote: > Hi all, > > I was hoping the community may be able to help me. I want to convert rgb > values to their L*A*B* value but I'm not sure of the best way to do so so the > setup will scale when the dataframe size increases. > > I saw on stackoverflow that skimage's conversion method > http://scikit-image.org/docs/dev/api/skimage.color.html?highlight=rgb2lab#skimage.color.rgb2lab > was suggested to be faster than alternatives but I'm having trouble > understanding how to use my dataframe as the input instead of an image and if > the conversion is successful how I can store the LAB values back into the > dataframe. At the moment my dataframe has a shape > > (827, 8) where Rgb_r, Rgb_g, Rgb_b are the column names I'm interested in, > you could think of the dataframe of 827 individual pixels with associated > metadata. > > Is it possible to pass a pandas dataframe to scikit-image color.rgb2.lab or > should I do row by row calculates for the situation where the number of rows > increases to possibly 200,000 or more > > Hope you can help me > > Michael > _______________________________________________ > scikit-image mailing list > scikit-image@python.org > https://mail.python.org/mailman/listinfo/scikit-image
_______________________________________________ scikit-image mailing list scikit-image@python.org https://mail.python.org/mailman/listinfo/scikit-image