LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2013, 01:48 PM   #1
Nabeel
Member
 
Registered: Nov 2009
Location: Pakistan
Distribution: Ubuntu
Posts: 294

Rep: Reputation: 17
Post Interlacing two images using numpy


Well I need help completing this interlacing function that takes two images and alternates their rows into a new image. I tried doing som
Code:
import sys, os
import numpy as np
import cv2

def interlace(evens, odds):
  '''Reconstruct the image by alternating rows of evens and odds.

  evens - a numpy array of shape (rows, columns, 3)  containing the even rows 
          of the output image.
  odds - a numpy array of shape (rows, columns, 3) containing the odd rows 
         of the output image.

  This function should return an image. Row 0 of the output image should be
  row 0 of evens. Row 1 of the output image should be row 0 of odds. Then
  row 1 of evens, then row 1 of odds, and so on.

  The resulting image will have as many rows as image 1 and 2 combined, equal
  to both in number of columns, and have 3 channels.
  '''
  i=0
  outimg = np.zeros([800,600] , 'uint8')
  # Implement your function here ---------------------------------------------
  while i <= (len(evens) + len(odds)):
    outimg[2*i] = evens[i]
    outimg[2*i + 1] = odds[i]
    i+=1
  #---------------------------------------------------------------------------
  return outimg
 
Old 04-03-2013, 12:05 PM   #2
thangqd
LQ Newbie
 
Registered: Apr 2013
Location: Vietnam
Posts: 1

Rep: Reputation: Disabled
Lightbulb Re: Interlacing two images using numpy

Code:
i = 0     
outimg = np.zeros((evens.shape[0]*2,evens.shape[1],3),dtype=np.uint8)  
while i <(evens.shape[0]):
    outimg[i*2] = evens[i]
    outimg[i*2+1] = odds[i]
    i+=1

Last edited by thangqd; 04-03-2013 at 12:11 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
NumPy Installation Dsw0002 Linux - Software 2 04-25-2011 07:11 PM
Fedora 5 screen interlacing problem after screensaver JohnLocke Linux - Newbie 0 04-24-2007 11:29 PM
Interlacing the lines of two text files khdubya Programming 3 02-03-2007 05:27 PM
Video Capture - Interlacing problems arw_opencv Linux - Hardware 3 12-03-2006 08:43 AM
Monitor Problem/Video Interlacing cultavix Linux - Hardware 0 01-12-2005 08:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration