Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Vertical Seam Removal
#1
hi everyone,
i need help in explaining this code, i know it is vertical seam removal but just need more details to explain what is really happening:::::

def delete_vertical_seam (img, path):
		
	"""
	Deletes the pixels in a vertical path from img
	@img: an input img
	@path: pixels to delete in a vertical path
	"""
	print_fn( "Deleting Vertical Seam..." )
	#raise Exception
	img_width, img_height = img.size
	i = Image.new(img.mode, (img_width-1, img_height))
	input  = img.load()
	output = i.load()
	path_set = set(path)
	seen_set = set()
	for x in range(img_width):
		for y in range(img_height):
			if (x,y) not in path_set and y not in seen_set:
				output[x,y] = input[x,y]
			elif (x,y) in path_set:
				seen_set.add(y)
			else:
				output[x-1,y] = input[x,y]
	
	print_fn( "Deletion Complete." )		
	return i
	
def add_vertical_seam(img, path):
	"""
	Adds the pixels in a vertical path from img
	@img: an input img
	@path: pixels to delete in a vertical path
	"""

	print_fn( "Adding Vertical Seam..." )
	img_width, img_height = img.size
	i = Image.new(img.mode, (img_width + 1, img_height) )
	input  = img.load()
	output = i.load()
	path_set = set(path)
	seen_set = set()
	for x in range(img_width):
		for y in range(img_height):
			if (x,y) not in path_set and y not in seen_set:
				output[x,y] = input[x,y]
			elif (x,y) in path_set and y not in seen_set:
				output[x,y] = input[x,y]
				seen_set.add( y )
				if x < img_width -2:
					output[x+1,y] = vector_avg(input[x,y], input[x+1,y])
				else:
					output[x+1,y] = vector_avg(input[x,y], input[x-1,y])
			else:
				output[x+1,y] = input[x,y]
				
	print_fn( "Addition Complete." )
	return i
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Removal of items in .txt using python nanakochan 8 1,664 Sep-02-2022, 04:58 PM
Last Post: perfringo
  Removal of duplicates teebee891 1 1,736 Feb-01-2021, 12:06 PM
Last Post: jefsummers
  how to draw vertical line on screen kalihotname 3 3,075 Aug-17-2020, 07:08 PM
Last Post: michael1789
  Seam Carving or Bilateral image filtering scott14 1 1,990 Dec-09-2018, 07:22 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020