Python code to find the roi

Were you able to process all images using that thresholding function? Are you sure that it crops the required region? It will be helpful if you can please upload the updated code snippet.