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("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"])])
            voxelCoord = worldToVoxelCoord(worldCoord, numpyOrigin, numpySpacing)
            voxelCoord = voxelCoord
            voxelWidth = 65
            print("VoxelCoord :",voxelCoord[0])
            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')
            #outputDir = 'patches/'
            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 in Python by anonymous
• 150 points

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

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 in Python by Gitika
• 42,520 points
+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,780 points
+1 vote
8 answers

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

Just for the record: >>> int('55063.000000') Traceback (most recent ...READ MORE

answered Aug 17 in Python by pakainfo
• 200 points
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,520 points
0 votes
2 answers

Error: Speech to Text Codec cannot decode the bytes in position

import speech_recognition as sr r = sr.Recognizer() audio ='C\Users\Desktop\audiofile1.wav' with ...READ MORE

answered Nov 27, 2018 in Python by Nabarupa Das
+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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,480 views
0 votes
0 answers