morphological-analysis

Calculate perimeter of numpy array

拜拜、爱过 提交于 2019-11-30 14:34:12
I want to calculate the perimeter of a given numpy array structure. With perimeter i mean the exact perimeter of the structure in the numpy array. The structure could include holes. My current aproach is something like this: import numpy a = numpy.zeros((6,6), dtype=numpy.int) a[1:5, 1:5] = 1;a[3,3] = 0 # Way 1 s = ndimage.generate_binary_structure(2,1) c = ndimage.binary_dilation(a,s).astype(a.dtype) b = c - a numpy.sum(b) # The result, however the hole is calculated as 1, although there are 4 edges # Way 2 b = ndimage.distance_transform_cdt(a == 0,metric='taxicab') == 1 b = b.astype(int)

How to parse a DOT file in Python

无人久伴 提交于 2019-11-30 06:49:13
问题 I have a transducer saved in the form of a DOT file. I can see a graphical representation of the graphs using gvedit, but what if I want to convert the DOT file to an executable transducer, so that I can test the transducer and see what strings it accepts and what it doesn't. In most of the tools I have seen in Openfst, Graphviz, and their Python extensions, DOT files are only used to create a graphical representation, but what if I want to parse the file to get an interactive program where I

Calculate perimeter of numpy array

倾然丶 夕夏残阳落幕 提交于 2019-11-29 20:16:30
问题 I want to calculate the perimeter of a given numpy array structure. With perimeter i mean the exact perimeter of the structure in the numpy array. The structure could include holes. My current aproach is something like this: import numpy a = numpy.zeros((6,6), dtype=numpy.int) a[1:5, 1:5] = 1;a[3,3] = 0 # Way 1 s = ndimage.generate_binary_structure(2,1) c = ndimage.binary_dilation(a,s).astype(a.dtype) b = c - a numpy.sum(b) # The result, however the hole is calculated as 1, although there are

Select largest object in an image

南楼画角 提交于 2019-11-27 14:50:26
I am trying to find the the largest object in an image and remove any other objects in the image that are smaller than it. This is what I have but I cannot get it to work. l=bwlabel(BW); %the area of all objects in the image is calculated stat = regionprops(l,'Area','PixelIdxList'); [maxValue,index] = max([stat.Area]); %remove any connected areas smaller than the biggest object BW2=bwareaopen(BW,[maxValue,index],8); subplot(5, 5, 4); imshow(BW2, []); I am working with digital mammograms such as these . I am trying to remove all objects from the image except for the breast region. Use

Select largest object in an image

余生长醉 提交于 2019-11-26 16:55:51
问题 I am trying to find the the largest object in an image and remove any other objects in the image that are smaller than it. This is what I have but I cannot get it to work. l=bwlabel(BW); %the area of all objects in the image is calculated stat = regionprops(l,'Area','PixelIdxList'); [maxValue,index] = max([stat.Area]); %remove any connected areas smaller than the biggest object BW2=bwareaopen(BW,[maxValue,index],8); subplot(5, 5, 4); imshow(BW2, []); I am working with digital mammograms such