Ошибка "TypeError: невозможно преобразовать серию в "при поиске интересующей области изображения в цикле for - PullRequest
0 голосов
/ 05 января 2020

Я новичок в науке о данных и пытаюсь обработать мои изображения. Ниже приведен код для пользовательского преобразователя, который я использую, чтобы сначала преобразовать изображение в оттенки серого, затем обрезать и затем изменить размер. Когда эти методы выполняются на отдельном изображении, такая ошибка не отображается. Но когда выполняется в For l oop, получается ошибка типа.

class Preprocessing(TransformerMixin):
    def __init__(self,dataset):
        # the constructor lets you specify which channel to select
        self.dataset=dataset
        X_data=[]
        #self.image_files=image_files

    def fit(self):
        # If the transformation depends on attributes of the training data
        # you can check those attributes here and store them on `self`.
        # However most transformers are "stateless" and immediately return self.
        return self

    def transform(self,image_files):
        # the transform method does the extraction
        X_data=[]
        for raw_image in image_files:
            image=cv2.imread(raw_image)
            image_gray=skimage.util.img_as_ubyte(skimage.color.rgb2grey(image[:,:,::-1]))
            row=self.dataset.index[self.dataset['Filename']==raw_image].tolist()
            row_data=self.dataset.iloc[row,:]
            Roi_X1=self.dataset.iloc[row,3]
            Roi_Y1=self.dataset.iloc[row,4]
            Roi_X2=self.dataset.iloc[row,5]
            Roi_Y2=self.dataset.iloc[row,6]
            region_of_interest=image_gray[int(Roi_X1):int(Roi_X2),int(Roi_Y1):int(Roi_Y2)]
            region_of_interest=skimage.util.img_as_ubyte(region_of_interest)
            image_resized = resize(region_of_interest, (64,64),anti_aliasing=True)
            image_resized=skimage.util.img_as_ubyte(image_resized)
            X_data.append(image_resized)


        return np.array(X_data, dtype='uint8')



dataset=pd.read_csv('Common.csv',sep=";")
image_files = [os.path.basename(x) for x in glob.glob('E:\Mtech\Machine learning\Assessment\My_data-Copy\Work_folder\*.ppm')] 
preprocessing_pipeline = Pipeline([('Image Preprocessing', Preprocessing(dataset))])
my_processed_images = preprocessing_pipeline.transform(image_files)

Ошибка отображается в строке

---> 26  region_of_interest=image_gray[int(Roi_X1):int(Roi_X2),int(Roi_Y1):int(Roi_Y2)]
as 
~\Anaconda3\lib\site-packages\pandas\core\series.py in wrapper(self) --> 131  raise TypeError("cannot convert the series to " "{0}".format(str(converter)))
TypeError: cannot convert the series to class 'int'
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...