I've been using scikit-image to classify road features with some success. See below: . I am having trouble doing the next step which is to classify the features. For example, let's say these features are located in the box (600, 800) and (1400, 600).
The code I'm using to extract the information is:
from skimage import io, segmentation as seg
color_image = io.imread(img)
plt.rcParams['image.cmap'] = 'spectral'
labels = seg.slic(color_image, n_segments=6, compactness=4)
The objective is to have a table in the following form:
Image, feature_type, starting_pixel, ending_pixel
001 a (600, 600), (1300, 700)
002 b (600, 600), (1100, 700)
002 undefined (700, 700), (900, 800)
feature_type
would be based on colours, ideally shoulders would be one colour, trees and brush would be another, etc.
How can I extract the data I need? (i.e: have scikit break the image into different components where I know the location of each component. I can then pass each component to a classifier which will identify what each component is) Thanks!
It is the first time I try that package.. I tried with a simpler image and I get more or less the right results:
from skimage import io, segmentation as seg
import matplotlib as plt
import numpy as np
color_image = io.imread('smallimg.jpg')
labels = seg.slic(color_image, n_segments=4, compactness=4)
for section in np.unique(labels):
rows, cols = np.where(labels == section)
print("Image="+str(section))
print("Top-Left pixel = {},{}".format(min(rows), min(cols)))
print("Bottom-Right pixel = {},{}".format(max(rows), max(cols)))
print("---")
Output:
Image=0
Top-Left pixel = 3,1
Bottom-Right pixel = 15,18
---
Image=1
Top-Left pixel = 26,1
Bottom-Right pixel = 34,18
---
Image=2
Top-Left pixel = 43,1
Bottom-Right pixel = 52,16
---
Image=3
Top-Left pixel = 0,0
Bottom-Right pixel = 59,19
---
Notice that the right-most pixel is not precisely what I mean because of the gradient. The last segment is the white background.
I tried with your image but I think you will have to get the segmentation right. I would use n_segments=7 if you want to get the 6 images + background.
I also see in the documentation about compactness: "This parameter depends strongly on image contrast and on the shapes of objects in the image.". So what you want could be difficult to achieve.
If you are plotting the six pictures on the image you show above, why don't you get those coordinates when you plot the pictures instead of applying segmentation to the end result?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With