c073 Ivp Lab9
c073 Ivp Lab9
:
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
while queue:
p, q = queue.pop(0)
# 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
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
Region Merging
Region Splitting