0% found this document useful (0 votes)
14 views3 pages

c073 Ivp Lab9

Uploaded by

Viha Shukla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

c073 Ivp Lab9

Uploaded by

Viha Shukla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

D.O.P.: L.D.O.S.

:
Roll No: C073 Name: Viha Shukla
Branch: BTI Comps Batch: C1
Date of Experiment: 16/10/24 Date of Submission: 16/10/24
Grade: Faculty: Prof Abhay Kolhe

Experiment No.: 9
Procedure:

TASK 1:
1. Read the input image.
2. Convert image to black and white.
3. Select the seed Pixel by using function ginput.
4. Apply 4-connectivity to check similarity constraint.
5. Display the original and the output images.

Code:
#C073
#Viha Shukla
#Aim: Write a Python code for implementation of Region based segmentation.
import numpy as np
import matplotlib.pyplot as plt
import cv2

def region_grow(image, seed_point, threshold=0):


"""Region growing segmentation using 4-connectivity."""
rows, cols = image.shape
g = np.zeros((rows, cols), dtype=np.uint8) # Initialize the
segmentation mask
g[seed_point[0], seed_point[1]] = 1 # Set the seed point
queue = [seed_point] # Initialize the queue

while queue:
p, q = queue.pop(0)

# Check 4-connected neighbors


for dy, dx in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
new_p, new_q = p + dy, q + dx

# Check boundaries
if 0 <= new_p < rows and 0 <= new_q < cols:
# Check if the pixel should be included in the region
if g[new_p, new_q] == 0 and image[new_p, new_q] ==
image[p, q]:
g[new_p, new_q] = 1 # Mark as part of the region
queue.append((new_p, new_q)) # Add to the queue
return g

def main():
# Step 1: Read the input image
image = cv2.imread('viha.jpg', cv2.IMREAD_GRAYSCALE) # Change to your
image path
if image is None:
print("Error: Could not read the image!")
return

# Step 2: Convert to binary


_, binary_image = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY) #
Convert to binary

# Automatically select the center of the image as the seed point


seed_point = (binary_image.shape[0] // 2, binary_image.shape[1] // 2)
# (y, x)

# Step 4: Apply region growing


segmented = region_grow(binary_image, seed_point)

# Step 5: Display results


plt.subplot(121)
plt.imshow(binary_image, cmap='gray')
plt.plot(seed_point[1], seed_point[0], 'r+', markersize=10) # Mark
seed point
plt.title('Original Image with Seed Point')
plt.axis('off')

plt.subplot(122)
plt.imshow(segmented, cmap='gray')
plt.title('Segmented Region')
plt.axis('off')

plt.tight_layout()
plt.show()

if __name__ == "__main__":
main()

Output
Conclusion:
I understood region growing and the method behind it. I was able to successfully complete the
experiment by understanding what the seed point value is. I have implemented the experiment on
Collab therefore I automatically considered the centre as seed point. Finally, 4-connectivity has
been verified.
Questions:
1. Enlist 04 applications of Region growing, Region Merging and Region Splitting method
of segmentation?

Region Growing

1. Medical Imaging: Segmenting organs/tumors in MRI/CT scans.


2. Satellite Imagery: Identifying land cover types in remote sensing.
3. Object Recognition: Isolating objects in images for tracking.
4. Texture Analysis: Analyzing surface textures in manufacturing.

Region Merging

1. Image Compression: Reducing data by merging similar regions.


2. Feature Extraction: Enhancing features for pattern recognition.
3. Environmental Monitoring: Analyzing land use changes in satellite images.
4. Video Segmentation: Merging frames to track moving objects.

Region Splitting

1. Scene Analysis: Breaking down images for detailed analysis.


2. Face Detection: Locating facial regions for security.
3. Medical Analysis: Identifying tissues in histopathology slides.
4. Object Detection: Improving efficiency in detecting objects in images.

You might also like