0

I am trying to isolate part of an image using connected component labeling. I am using scipy's ndimage.label on this image: enter image description here

for some reason the result is this: enter image description here

The part of the image that actually interests me is the white triangle in the upper right corner, which for some reason is labelled as background. What am I doing wrong?

The code I'm using is:

import numpy as np 
from scipy import misc
from scipy import ndimage
import matplotlib.pyplot as plt
from skimage.filters import threshold_otsu
from skimage.measure import label
from skimage.morphology import closing, square
from skimage.color import label2rgb
from scipy.ndimage.measurements import label

im = misc.imread('20588046_024ee3569b2605dc_MG_R_ML_ANON.jpg')
med_im = ndimage.median_filter(im1, 3)
bw = closing(med_im > 170, square(3))
fill_bw = ndimage.binary_fill_holes(bw)
s = [[1, 1, 1],
     [1, 1, 1],
     [1, 1, 1]]
label_im, nb_labels = ndimage.label(fill_bw, structure=s)
sizes = ndimage.sum(fill_bw, label_im, range(nb_labels + 1))
mask_size = sizes < 1000
remove_pixel = mask_size[label_im]
label_im[remove_pixel] = 0

plt.imshow(label_im, cmap=plt.cm.spectral)
plt.show()

I've also tried using it without the structure, and I'm getting the same result. I am new to python so I apologiza if the code is a little messy

Mira
  • 1
  • 1
  • 1
    Can you post a block of code that shows what you're doing? This problem may be data-specific, but it would help diagnose what's happening if we have a bit more context. – Thomas Kimber Feb 07 '18 at 19:15
  • Answering "What am I doing wrong?" without seeing what you're doing is like playing the lottery. Maybe we get lucky and guess right, but it's highly unlikely. – Cris Luengo Feb 08 '18 at 02:34
  • You're right. Don't know why I thought I would get any help without posting the code itself. – Mira Feb 08 '18 at 15:41

0 Answers0