0
import matplotlib.pyplot as plt
import pandas as pd
from skimage import io, morphology, segmentation
from PIL import Image
from skimage.color import rgb2gray
from scipy.ndimage import gaussian_filter
from skimage.filters import threshold_yen
import numpy as np

filepath1 = r'C:\Users\marzo\Downloads\frogblood.jpg'
filepath2 = r'C:\Users\marzo\Downloads\fishblood.jpg'

img1 = io.imread(filepath1)
img2 = io.imread(filepath2)

img1 = rgb2gray(img1)
img2 = rgb2gray(img2)

img1 = gaussian_filter(img1, sigma=1)
img2 = gaussian_filter(img2, sigma=1)

block_size1 = 51
block_size2 = 51

threshold1 = threshold_yen(img1, block_size1)
threshold2 = threshold_yen(img2, block_size2)

mask = img1 < threshold1 * 0.3
mask2 = img2 < threshold2 * 0.89

mask = morphology.remove_small_objects(mask, 400)
mask2 = morphology.remove_small_objects(mask2, 10000)
mask = morphology.remove_small_holes(mask, 10000)
mask2 = morphology.remove_small_holes(mask2, 2)

plt.title('Frog Blood_20x')
plt.imshow(img1)
plt.show()
plt.title('Fish Blood_20x')
plt.imshow(img2)
plt.show()

I am trying to remove small holes and objects and use threshold_yen but it is not doing anything at all. Im not getting errors aswell, is the import wrong or am i missing somwthing here

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
codeman
  • 1
  • 2
  • 1
    Your `imshow` calls are not showing the results of the threshold, only the inputs. – Cris Luengo Feb 09 '23 at 18:16
  • @CrisLuengo what do you mean, what am i supposed to add to imshow. Should i add mask or threshold – codeman Feb 09 '23 at 20:23
  • You are showing `img1` and `img2`. Look at what you last assigned to these variables. It's not the result of the threshold! It seems to me that `mask` and `mask2` are the images you wanted to look at. So put those variables into the `imshow` function. – Cris Luengo Feb 09 '23 at 21:16

0 Answers0