Reputation: 41
I'm working on a project to calculate the level of a chest deformity. For that, I need to find the inner contour of the chest from the tomography; however, I don't know how to select the inner contour.
First, I converted the image to binary and applied a threshold.
import cv2
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
def process_and_plot(image_path):
def process(image_path):
image = cv2.imread(image_path)
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred_image = cv2.GaussianBlur(gray_image, (5, 5), 0)
_, binary_image = cv2.threshold(blurred_image, 127, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
return binary_image
fig, axes = plt.subplots(1, 2, figsize=(10, 5))
img = Image.open(image_path)
axes[0].imshow(img, cmap='gray')
axes[0].set_title('Original Image')
processed_image = process(image_path)
axes[1].imshow(processed_image, cmap='gray')
axes[1].set_title('Processed Image')
plt.show()
process_and_plot('test.jpeg')
What I'm expecting is to get the red contour.
Upvotes: 0
Views: 66