0

I'm trying to find out ROI for an image dataset. I'm able to find ROI for a single image, but when it comes to the whole dataset or multiple images I can't do it.

I tried to use different code from the internet, but nothing worked. `

import cv2
import numpy as np
import os
import random
from matplotlib import pyplot as plt
import matplotlib.image as mpimg

img_folder=r'Shrimp/train/Resized_Dataset'
img_dir = r'Cropped_shrimp'
for i in range(30):
    file = random.choice(os.listdir(img_folder))
    image_path= os.path.join(img_folder, file)
    img=mpimg.imread(image_path)
    ax=plt.subplot(1,30,i+1)
    ax.title.set_text(file)
    plt.imshow(img)
    
roi = cv2.selectROI(img_folder)

ROI_image = img_folder[int(r[1]):int(r[1]+r[3]),
                      int(r[0]):int(r[0]+r[2])]

cv2.imshow("ROI_image", ROI_image)
cv2.waitKey(0)

os.chdir(img_dir)

cv2.imwrite("ROI_image", JPG)

` This is my last approach. I think there're lots of mistake because I'm trying this for the first time.

717896
  • 1
  • Can you explain a bit what exactly you're trying to do? It looks like you are trying to plot 30 images. What do you want the result to look like? Can you find an example of a similar plot? – Matt Hall Oct 27 '22 at 20:05
  • I'm trying to read an image dataset and then select ROI for each image and save them to another folder. I just plot 30 images for showing the original images nothing else. – 717896 Oct 27 '22 at 20:59
  • I just need to know how to select ROI for multiple images in a folder and save them to another folder. – 717896 Oct 27 '22 at 21:10
  • try to explain without using the term "ROI". explain _that_ concept, don't just try to use the word and hope we'll know what you mean. -- [tour], [ask], [mre], [help/on-topic] – Christoph Rackwitz Oct 27 '22 at 21:42
  • ROI = Region Of Interest and I'm trying to select the region of interest of multiple images from a folder. – 717896 Oct 27 '22 at 22:10
  • Do the same thing you are doing on one image on all the rest. Loop over your folder of images (or list of images) and repeat the same thing. Search Google for how to read and or write to a folder of images in Python. – fmw42 Oct 27 '22 at 22:24

0 Answers0