pytorch / pytorch/vision

How to Crop single image before calling torchvision.utils.save_image, If I am using PIL lib Image.crop(....) method then image quality degrade.

Open
#1,395 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

module: utils
Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

 vutils.save_image(fixed_fake.data,outputpath , normalize=True)
print("output path",outputpath)
img = Image.open(outputpath)
noOfRow = 5
noOfColumn = 8
x1 = 2
y1 = 2
x2 = 130
y2 = 130
folder = file_batch

for i in range(0, noOfColumn):
    dest_dir = file_batch[i].split("/")[7]
    if not os.path.exists(outf+"/"+dest_dir):
        os.mkdir(outf+"/"+dest_dir)
    for j in range(1, noOfRow + 1):
        area = (x1, y1, x2, y2)
        cropped_img = img.crop(area)
        imgName = "{}{}".format(i, j)
        cropped_img.save(os.path.join(outf+dest_dir,filename))
        y1 = y1 + 130
        y2 = y2 + 130
    x1 = x1 + 130
    x2 = x2 + 130
   y1 = 2
    y2 = 130

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided workflow with torchvision.utils.save_image, PIL Image.open, Image.crop, and cropped_img.save. Compare the saved image before and after cropping to determine where quality changes; done means the source of the degradation is identified and the expected image quality or handling is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.