vedant gala
vedant gala

Reputation: 428

Detecting the presence of a black areas in a grayscale image

My objective is a vague one, and as such I don't have any reproducible code for the same.

I want to develop a network that I train with certain types of grey scale images that will detect the areas which are above a certain grayscale intensity threshold.

How should I proceed further with this? Do I need a neural network for this?

Below are some sample images. The one on the extreme left is what it should look like, the one in the middle is when it finds out that there are some black lines (not exactly black, but above some threshold of a grayscale intensity) and the one on the extreme right is what I expect the output of my code to be.

PS This is particularly of interest when detecting cracks in CT scans, which show up as dark black blobs/lines among the other grayscale background

enter image description here

Upvotes: 1

Views: 2978

Answers (1)

T A
T A

Reputation: 1756

This is very trivial and you will definitely not need a neural network to solve this. If you are working with grayscale images and know the intensity threshold you are interested in (e.g you allow an intensity value up to 3) you can just do a simple threshold operation to identify the black regions.

This would probably also work on your ct scan application, presupposed these "cracks" are always of very low intensity.

E.g. for a ct-image where I applied your "cracks" in your example image, threshold these cracks would work pretty well (you only get some background noise/artifacts). See the following OpenCV snipped:

import numpy as np
import cv2

# Load an color image in grayscale
img = cv2.imread('chest-ct-lungs.jpg',0)
ret,thresh = cv2.threshold(img,3,255,cv2.THRESH_BINARY)
cv2.imwrite('output.png',thresh)

input:

enter image description here

original image source: www.radiologyinfo.org

output:

enter image description here

As you see this is literally just 3 lines of code, don't always assume you have to use neural networks for everything, sometimes its best to just solve a image-processing problem the "old fashioned way". Especially if the problem is a trivial one.

Upvotes: 3

Related Questions