top of page

Manipulating Images

  • 작성자 사진: Shin Yoonah, Yoonah
    Shin Yoonah, Yoonah
  • 2022년 7월 16일
  • 2분 분량

최종 수정일: 2022년 8월 8일

I'm going to introduce you about two functions of manipulating images


1.Copying an Image

Copying which allows you to create a new image independent of the original is frequently used in our life. But, do you know how it works?


This is how computer works when you copy an image

*assume baboon as a png image*


from PIL import image Picture of Memory

ree

import cv2

import numpy as np

baboon = cv2.imread("baboon.png") ----> Stored in 00100010 memory

baboon = np.array(Image.open("baboon.png"))


Use id function to find the object's memory address

id(baboon):00100010


A=baboon ----> Assign the baboon array to "A" (Copying)

id(A):00100010 ---> The memory address is same as the original


B=baboon.copy()

id(B):10101010 ----> The memory address is different







See how the memory address works!!


baboon[;,;,] = 0 -----> Set all the elements to the baboon array to ZERO


The array "A" will change as it points to the same locations in memory

"Baboon" "A" "B"

ree

00100010 00100010 10101010




*Both the baboon array of array "A" will be zero but because we used the copy method array "B" will be unaffected*




2.Flipping images

= changes the image orientation


Flip an image by changing the index value of pixel or intensity

ex) Convert the column indexes to row indexes the image will have a different orientation


For color images *Cube format*

= Convert all the color channels at the same time


Flipping images using PIL & Open CV


1.Using PIL

from PIL import ImageOps

im_flip = ImageOps.flip(Image) ----> flip function to flip the image

im_mirror = ImageOps.mirror(Image) -----> mirror the image using the mirror function

image.transpose(Image.FLIP_TOP_BUTTOM) ----> using transpose() method/the image module has built in attributes to

describe the type of flip


2.Using Open CV

import cv2

im_flip = cv2.flip(Image,0) ----> parameter = flipcode/if flipcode is 0, flip vertically around the 4 axis

im_flip = cv2.rotate(Image, cv2.Rotate_90_CLOCKWISE) ---> rotate() function; open CV module has built-in

attributes to describe the type of flip

---> Values are represented by integers



Copyright Coursera All rights reserved


댓글


bottom of page