Python Forum
My objective is to get the shape parameters of the particles in attached image
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My objective is to get the shape parameters of the particles in attached image
#1
while using cv2.drawContours to display the counters, the contours are not displayed. While using cv.2 drawContours, I am getting no errors. As I am new to python, I am not able to figure out what the code is lacking. Thanks in advance for help.
My code is as follow:
import matplotlib
import numpy as np 
import matplotlib.pyplot as plt
import skimage 
from skimage import io
from skimage import filters
from skimage.color import rgb2gray
import cv2
from skimage import morphology
from skimage.morphology import disk
from  scipy import ndimage

testimage = io.imread('testimage.jpg');
grayscale = rgb2gray(testimage)

threshold_value = filters.threshold_otsu(grayscale)
threshold_value

nrows, ncols = grayscale.shape
dim = (nrows, ncols)
img_bin = np.zeros(dim)

for i in range(0,nrows,1):
    for j in range(0,ncols,1):
        if (grayscale[i][j] > threshold_value):
            img_bin[i][j] = 255;
            
img_bin = img_bin.astype('uint8')
img_bin3 = morphology.remove_small_objects(img_bin, min_size=35, connectivity=4)

radius = 2
selem = disk(radius)

img3 = cv2.dilate(img_bin, selem, iterations= 1)
img4 = cv2.erode(img3, selem, iterations= 1)
fill_particles = ndimage.binary_fill_holes(img4)
img5 = ndimage.median_filter(fill_particles, [1,1])

plt.imshow(fill_particles, cmap = 'gray')      

img5 = img5.astype('uint8')
_,contours, hierarchy = cv2.findContours(img5, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
print("Number of Contours found = " + str(len(contours))) 

cv2.drawContours(img5, contours, -1, (0, 255, 0), 20)
plt.imshow(img5, 'gray')

while I am trying to upload the image, the URL link is coming but the image is on my laptop. I have written the URL for image from my laptop. But the image is not getting flashed along with question?
Please guide me to upload the image. Sorry for the request.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  output shape problem with np.arange alan6690 5 701 Dec-26-2023, 05:44 PM
Last Post: deanhystad
  simplekml change shape&color issac_n 2 2,849 Aug-20-2022, 07:15 PM
Last Post: Joseph_Paintsil
  Can't properly shape an array maaaa2401 3 2,336 Dec-18-2020, 09:32 AM
Last Post: maaaa2401
  ValueError: shape mismatched: objects cannot be broadcast to a single shape Laplace12 0 4,523 Jul-14-2020, 11:45 AM
Last Post: Laplace12
  Receiving ValueError("bad input shape {0}".format(shape)) error SuryaCitizen 2 3,516 Jun-01-2020, 06:45 AM
Last Post: pyzyx3qwerty
  Spawning a new process that is not attached to python cman234 3 1,921 Apr-25-2020, 05:24 PM
Last Post: cman234
  Fill a value in triangle shape in Matrix lynx 0 1,887 Dec-07-2019, 06:32 AM
Last Post: lynx
  Parsing Attached .MSG Files with Python3 ericl42 1 3,684 Apr-12-2019, 06:28 PM
Last Post: ericl42
Question [Help] Convert integer to Roman numerals? {Screenshot attached} vanicci 10 9,191 Aug-06-2018, 05:19 PM
Last Post: vanicci
  [Help] sorted() in while loop with user's input() {Screenshot attached} vanicci 5 4,024 Aug-04-2018, 08:59 PM
Last Post: vanicci

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020