I have a segmented mask of vessel and original image. Trying to use gaussian function to erode out that region into a lower intensity. I read the image and mask segment (black/white) then pass it over to erode_vasc
; there I just average it out. Averaging is leaving a streak when I convert to gray. If I can get that into a lowered intensity so that it blends e.g. if I can convolve that region of lines to lower intensity is what I am after.
I took 2 images - original and segmented imaged and called this program. Issue is the line while in RGB is fine - it is hardly visible but once I push this to other image conversions, it starts to be visible.
import os
import os.path as osp
import cv2
import sys
import numpy as np
from PIL import Image
from skimage import io, img_as_float
from skimage.io import imshow
from scipy import signal
from skimage.color import rgb2yuv, rgb2hsv, rgb2gray, yuv2rgb, hsv2rgb
from skimage.transform import resize
import math
from tqdm import tqdm
import matplotlib.pyplot as plt
import time
def avg_vessel(boxarea_v, channel_v, mask_v):
boxarea = boxarea_v.flatten()
channel = channel_v.flatten()
mask = mask_v.flatten()
# selecting all pixels with mask value greater than 0.1
AOI = (mask>0.1)
retval = np.zeros(boxarea.shape)
# assign local average to selected pixels
retval[AOI] = boxarea[AOI]
# keep remaining ones same as original
retval[~AOI] = channel[~AOI]
return retval.reshape(channel_v.shape)
# removes vessel from each channel
def erode_vasc(channel,mask):
bordertype = 'fill'
blursqr = (signal.convolve2d(channel,np.ones((8,8)),boundary=bordertype,mode='same'))/64
--> blursqr = np.ones(blursqr,float32)/64 <-- using this for average
avg_channel = np.zeros(channel.shape)
avg_channel = avg_vessel(blursqr, channel, mask)
channel = avg_channel
# given an image and mask, calls remove_vessel on each channel of image
def erode_image(orig_im, mask):
# Erode vasculature on red channel
chr = erode_vasc(orig_im[:,:,0],mask)
# Erode vasculature on blue channel
chg = erode_vasc(orig_im[:,:,1],mask)
# Erode vasculature on green channel
chb = erode_vasc(orig_im[:,:,2],mask)
eroded_image = np.dstack((np.rint(abs(chr)),
np.rint(abs(chg)),
np.rint(abs(chb)))) /255
plt.figure(num=None, figsize=(8,6), dpi = 80)
plt.imshow(eroded_image)
How can one replace the average valuation with a gaussian kernel? How to calculate a Gaussian kernel matrix efficiently in numpy? is not complete.