Error tile cannot extend outside the image How to save patches without this error

+1 vote
def nodule_detect(nodules,j,numpyImage, numpyOrigin, numpySpacing):
    #g = "input/subset"+str(k)+"/"+j
    #numpyImage, numpyOrigin, numpySpacing = load_itk_image(j)
    #jj = j.split("/")
    #jj = jj[-1]
    numpyImage = normalize(numpyImage)
    print("Inside nodule-detect",numpyImage)
    for i in range(len(nodules)):
        vals = nodules.loc[i]
        #print(j)
        #print("In nodule-detect")
        jj = j.split("/")
        jj = jj[-1]
        if(vals['seriesuid'] == (jj.replace(".mhd",""))):
            print("Inside the nodule")
            worldCoord = np.asarray([float(vals["coordX"]),float(vals["coordY"]),float(vals["coordZ"])])
            print(worldCoord)
            voxelCoord = worldToVoxelCoord(worldCoord, numpyOrigin, numpySpacing)
            print(voxelCoord)
            voxelCoord = voxelCoord
            voxelWidth = 65
            print("VoxelCoord :",voxelCoord[0])
            print("Welcome")
            patch = numpyImage[int(voxelCoord[0]),int(voxelCoord[1])- int(voxelWidth/2):int(voxelCoord[1])+int(voxelWidth/2),int(voxelCoord[2])-int(voxelWidth/2):int(voxelCoord[2])+int(voxelWidth/2)]
            patch = normalizePlanes(patch)
            print (worldCoord)
            print (voxelCoord)
            print (patch)
            outputDir = 'patches/'
            plt.imshow(patch, cmap='gray')
            plt.show()
            #outputDir = 'patches/'
            plt.savefig('patch'+".png")
            Image.fromarray(patch*255).convert('L').save(os.path.join(outputDir,'patch_'+ str(worldCoord[0]) + '_' + str(worldCoord[1]) + '_' + str(worldCoord[2]) +'.tiff')) - at the end of this , error is coming as mentioned above
Jan 28, 2020 in Python by anonymous
• 150 points
1,733 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

How to save an image locally using Python in which we already know the URL address?

Hi, @Roshni, The following code is used to ...READ MORE

answered Jun 26, 2020 in Python by Gitika
• 65,890 points
1,878 views
+1 vote
2 answers

How to resize the image canvas to maintain a square aspect ratio

down voteacceptedUsing OpenCVYou can use resize() in OpenCV to ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,720 points

edited Jul 11, 2023 by Khan Sarfaraz 1,628 views
+2 votes
10 answers

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

The following are totally acceptable in python: passing ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,560 points
409,066 views
0 votes
1 answer

How to save Numpy array as image in python?

If you have matplotlib, you can do: import ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,560 points
8,935 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,394 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP