PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 27, 2022

[FIXED] How to cut 25% of image from each side

 July 27, 2022     crop, matplotlib, python     No comments   

Issue

I'm trying to find a way to cut 25% from each side of the image. I was trying with this cutted_data = data[1:645,1:645] but it's not what I'm looking for.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as img

image_name = 'image.jpg'

data = plt.imread('image.jpg')
cutted_data = data[...?]

print(data)
print(np.shape(data))

plt.subplot(231)
plt.imshow(data)
plt.axis('off')
plt.title('Obraz w naturalnych kolorach')

plt.subplot(234)
plt.imshow(cutted_data)
plt.axis('off')
plt.title('Przycięty obraz')

plt.show()

Solution

You can try:

data = plt.imread('image.jpg')
rows, cols = data.shape[:2]
cut_data = data[rows//4:-rows//4, cols//4:-cols//4]


Answered By - Quang Hoang
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing