def rotate(iImg, angle): LOG(None, 'Rotation Angle: ' + str(angle)) if 90 == angle: oImg = Image(Image.BY_DATA, cv2.rotate(iImg.data,rotateCode = cv2.ROTATE_90_CLOCKWISE)) elif 180 == angle: oImg = Image(Image.BY_DATA, cv2.rotate(iImg.data,rotateCode = cv2.ROTATE_180)) elif 270 == angle: oImg = Image(Image.BY_DATA, cv2.rotate(iImg.data,rotateCode = cv2.ROTATE_90_COUNTERCLOCKWISE)) else: # Calculate Rotation Matrix h, w, _ = iImg.data.shape cx = w >> 1 cy = h >> 1 rotMatrix = cv2.getRotationMatrix2D((w >> 1, h >> 1), -angle, 1.0) cos = np.abs(rotMatrix[0, 0]) sin = np.abs(rotMatrix[0, 1]) # compute the new bounding dimensions of the image nW = int((h * sin) + (w * cos)) nH = int((h * cos) + (w * sin)) # adjust the rotation matrix to take into account translation rotMatrix[0, 2] += (nW / 2) - cx rotMatrix[1, 2] += (nH / 2) - cy # perform the actual rotation and return the image oImg = Image(Image.BY_DATA, cv2.warpAffine(iImg.data, rotMatrix, (nW, nH))) return oImg
def load(cls, path, world, fargs): path = Path(path) thumbnail = Image(path / 'S0.jpg', MEDIUM) screenshots = (Image(path / 'S{}.jpg'.format(i), MEDIUM) for i in range(1, 6)) if world else None panorama = Image(path / 'S6.jpg', PANORAMA) if world else None icon = Image(path / 'S7.jpg', L_SQ) if world and (path / 'S7.jpg').is_file() else None return cls(thumbnail, icon, panorama, screenshots, fargs)
def main(): filename = input("Enter the image file name: ") image = Image(filename) #lighten(image, 20) example #darken(image2, 64) example colorFilter(image3, (255, 0, 0)) #example image.draw()
def __init__(self, width, height): self.img = Image() self.width = width self.height = height self.length = self.height*self.width self.A = 0 #matrix variância self.m = 0 #vetor média
def main(filename="example.gif"): image = Image(filename) print("Close to continue.") image.draw() grayscale(image) print("Close window to quit.") image.draw()
def main(filename="bdbh.gif"): image = Image(filename) image.draw() # blackandWhite(image) # image.draw()
def load(cls, path, name, uuid_s=None, languages=None): path = Path(path) new_path = path.parents[0] new_path = new_path / "world" if new_path.is_dir(): worlds = list(filter(is_world, new_path.iterdir())) if len(worlds) > 1: raise MultipleWorldsError(new_path) if len(worlds) == 1: w = worlds[0] new_path = w if languages is None: languages = ['en_US'] cap_name = upper_name(name) skins = [] texts = SkinTexts(name, languages=languages, copy_langs=None) for p in path.glob('*.png'): skin_name = p.stem img = Image(p, ANY) skin = Skin(skin_name, img) texts.add_skin(skin) skins.append(skin) return cls(new_path, skins, name, cap_name, uuid_s, texts)
def main(): filename = input("Enter the image file name: ") # image1 = Image(filename) # grayscale1(image1) image2 = Image(filename) grayscale2(image2) image.draw()
def convertFile(self): try: if self._pictureThere: # Converts the argument image to black and white from images import Image image = Image(self._textField.getText()) blackPixel = (0, 0, 0) whitePixel = (255, 255, 255) for y in range(image.getHeight()): for x in range(image.getWidth()): (r, g, b) = image.getPixel(x, y) average = (r + g + b) / 3 if average < 128: image.setPixel(x, y, blackPixel) else: image.setPixel(x, y, whitePixel) image.draw() else: print("uhhhhhhhh no image there") except Exception: self.messageBox( title="ERROR", message= "THERE IS NO FILE INPUTTED. \n PLEASE ENTER A FILE NAME.")
def main(filename="smokey.gif"): image = Image(filename) print "Close the image window to continue. " image.draw() blackAndWhite(image) print "Close the image window to quit. " image.draw()
def main(filename="smokey.gif"): image = Image(filename) print("Close the image window to continue.") image.draw() grayscale(image) print("Close the image window to quit.") image.draw()
def main(): filename = input("Enter the image file name: ") image = Image(filename) print("Close the window to view the changes to the image.") image.draw() newimage = enlarge(image, 2) newimage.draw()
def enlarge(image, factor): """Builds and returns a copy of the image which is larger by the factor.""" oldWidth = image.getWidth() oldHeight = image.getHeight() new = Image(oldWidth * factor, oldHeight * factor) oldY = 0 newY = 0 while oldY < oldHeight: for countY in range(factor): oldLeft = 0 oldRight = oldWidth - 1 newLeft = 0 newRight = new.getWidth() - 1 while oldLeft < oldRight: leftPixel = image.getPixel(oldLeft, oldY) rightPixel = image.getPixel(oldRight, oldY) for count in range(factor): new.setPixel(newLeft, newY, leftPixel) new.setPixel(newRight, newY, rightPixel) newLeft += 1 newRight -= 1 oldLeft += 1 oldRight -= 1 newY += 1 oldY += 1 return new
def main(): filename = input("Enter the image file name: ") image = Image(filename) grayscale(image) image.draw() sepia(image) image.draw()
def main(): colors = [(255, 0, 0), (255, 255, 0), (0, 255, 0), (0, 255, 255), (0, 0, 255), (255, 0, 255)] img = Image(500, 200) rainbow(img, colors) img.draw()
def main(filename): image = Image(filename) print('Close the image window to continue. ') image.draw() invertImage(image) print('Close the image window to quit. ') image.draw()
def testSharpen(name="smokey.gif", degree=50, amount=20): """Makes image appear crisper.""" image = Image(name) print("Close the image window to see the transformation") image.draw() image2 = sharpen(image, degree, amount) image2.draw()
def __init__(self, odooenv, name): """ Busca el cliente en la estructura de directorios, pero si no lo encuentra pide un directorio donde esta el repo que lo contiene """ # parent es siempre un objeto OdooEnv self._parent = odooenv self._name = name # si estamos en test accedo a data if name[0:5] == 'test_': path = os.path.dirname(os.path.abspath(__file__)) path = path.replace('scripts', 'data') manifest = self.get_manifest(path) else: manifest = self.get_manifest(BASE_DIR) if not manifest: msg.inf('Can not find client {} in this host. Please provide path ' 'to repo\n where it is or hit Enter to exit.' '\n'.format(self._name)) path = raw_input('path = ') manifest = self.get_manifest(path) if not manifest: msg.err('Can not find client {} in this host'.format(name)) msg.inf('Client found!') msg.inf('Name {}\nversion {}\n'.format(manifest.get('name'), manifest.get('version'))) # Chequar que este todo bien if not manifest.get('docker'): msg.err('No images in manifest {}'.format(self.name)) if not manifest.get('repos'): msg.err('No repos in manifest {}'.format(self.name)) self._port = manifest.get('port') if not self._port: msg.err('No port in manifest {}'.format(self.name)) self._version = manifest.get('version')[0:3] if not self._version: msg.err('No version tag in manifest {}'.format(self.name)) # Crear imagenes y repos self._repos = [] for rep in manifest.get('repos'): self._repos.append(Repo(rep)) self._images = [] for img in manifest.get('docker'): self._images.append(Image(img)) # todo codigo repetido # get first word of name in lowercase name = manifest.get('name').lower() if not self._name == name.split()[0]: msg.err('You intend to install client {} but in manifest, ' 'the name is {}'.format(self._name, manifest.get('name')))
def testDetect(name="smokey.gif", amount=20): """Loads and draws an image, then detects edges and redraws it.""" image = Image(name) print("Close the image window to see the transformation") image.draw() image2 = detectEdges(image, amount) image2.draw()
def testBlackAndWhite(name="smokey.gif"): """Loads and draws an image, then converts it to black and white and redraws it.""" image = Image(name) print("Close the image window to see the transformation") image.draw() blackAndWhite(image) image.draw()
def testGrayscale(name="smokey.gif"): """Loads and draws an image, converts it to pyschologically correct grayscale, and redraws it.""" image = Image(name) print("Close the image window to see the transformation") image.draw() grayscale(image) image.draw()
def showPicInfo(self): from images import Image image = Image(self._textField.getText()) w = image.getWidth() h = image.getHeight() print(self._textField.getText()) print("The width is ", w) print("The height is ", h)
def main(filename="example.gif"): image = Image(filename) print("Close to continue.") image.draw() color = (82, 50, 168) posterize(image, color) print("Close window to quit.") image.draw()
def flip(iImg, flipAxis): if (FLIP_V == flipAxis) or (FLIP_H == flipAxis): oImg = Image(Image.BY_DATA, cv2.flip(iImg.data, flipAxis)) else: oImg = None return oImg
def testSepia(name="smokey.gif"): """Loads and draws an image, converts it to grayscale, then converts it to sepia, and redraws it.""" image = Image(name) print("Close the image window to see the transformation") image.draw() sepia(image) image.draw()
def main(): filename = input("Enter the image file name: ") red = int(input("Enter an integer [0..255] for red: ")) green = int(input("Enter an integer [0..255] for green: ")) blue = int(input("Enter an integer [0..255] for blue: ")) image = Image(filename) posterize(image, (red, green, blue)) image.draw()
def testPosterize(name="smokey.gif", triple=(0, 0, 0)): """Loads and draws an image, then converts it to a color of the user's choosing and white, and redraws it.""" image = Image(name) print("Close the image window to see the transformation") image.draw() posterize(image, triple) image.draw()
def main(): #Asking for an image to use for the conversions filename = raw_input("Enter the filename of a gif: ") image = Image(filename) img = image.clone() gewd = False while not gewd: #Printing and asking for options print "%-2d%s" % (0, "black and white conversion") print "%-2d%s" % (1, "inverse conversion") print "%-2d%s" % (2, "sepia conversion") print "%-2d%s" % (3, "reset image") print "%-2d%s" % (4, "load new image") print "%-2d%s" % (5, "quit") print "\n" option = raw_input("Enter an option: ") correctInput = False while correctInput == False: #If the option is a number between 0 and 3 if not option.isalpha() and int(option) >= 0 and int(option) < 6: print "Thanks for coherent input bro!" correctInput = True else: option = raw_input( "Enter a numerical option BETWEEN 0 and 5: ") option = int(option) if option != 5: #If the user has wished the image to be restored to its initial state if option == 3: #Cloning the original image and overwriting all previously done conversions img = image.clone() elif option == 4: filename = raw_input( "Enter a filename of the image you wish to alter(gif please): " ) image = Image(filename) img = image.clone() else: #Perform other tasks on the current image computeOptions(option, img) print "Close the image to continue!" img.draw() else: gewd = True print "\nHave a nice day!"
def main(): filename = input("Type the image you would like to use ") image = Image(filename) grayscale(image) print("Close the image window to continue. ") image.draw() sepia(image) print("Close the image window to quit. ") image.draw()
def rotateRight(image): """Rotates the image 90 degrees """ newImage = Image(image.getHeight(), image.getWidth()) for y in range(image.getHeight()): for x in range(image.getWidth()): (r, g, b) = image.getPixel(x, y) newImage.setPixel(image.getHeight() - y - 1, x, (r, g, b)) return newImage