def decode(img): """ A decoding function that gets all of the alpha values associated with all the pixels in our image which are somewhere between 0-255 and converts that alpha value to a character. """ ints = [] #A list of ints that will contain all of our alpha values. width, height = img.size #Get the width and the height of my image. pixelData = ImageUtilities.getPixelList(img) #Get all of the pixels in the image and put them into a list. for y in range(height): #Iterate across the pixels from top to bottom. for x in range(width): #Iterate across out image from left to right. alpha = ImageUtilities.getAlphaFromList(img, pixelData, x, y) #Referenced the dumped contents if (alpha == 255): #If the alpha of our pixel is 255.... continue #I don't want 255 values because that means that is not part of my message. ints.append(alpha) #Get the alpha value and append it to my list of ints. msg = "" #Make an empty string to store our decoded message. for value in ints: #Iterate across my list of ints. (For each int in my list...) msg += chr(value) #Convert my int to it's character value and add it back to my message. return msg
def getImageRepresentation(self): print("getImageRepresentation:", self._bestReferenceName) text = self._bestReferenceName size = 100 canvas = Image.new("RGB", [size, size], (255, 255, 255)) draw = ImageDraw.Draw(canvas) textWidth, textHeight = draw.textsize(text) offset = (5, 5) white = "#000000" draw.text(offset, text, fill=white) ret = 255.0 - np.asarray(canvas) middleOfImage = np.array([[50.0, 50.0]]) cloudPoints = np.dot( self._lastCloud, self._transformation[1]) + self._transformation[2] + middleOfImage referencePoints = self._referenceClouds[ self._bestReferenceName] + middleOfImage ImageUtilities.addPointsToImage(ret, cloudPoints, 0) ImageUtilities.addPointsToImage(ret, referencePoints, 1) return ret
def PointCloudToRgbImage(cloud, color): if 0 == cloud.size(): return np.zeros((10, 10, 3)) cols = int(cloud.max()[1] + cloud.min()[1]) + 1 rows = int(cloud.max()[0] + cloud.min()[0]) + 1 ret = np.zeros((rows, cols, 3)) ImageUtilities.addPointsToImage(ret, cloud, color) return ret
def super_resolution_dataset(self, super_resolutioned_image, ratio, dataset): resized_image = super_resolutioned_image.resize(ratio) patches, patches_dc = resized_image.get_patches(interval=4) hr_patches = dataset.query(patches) hr_patches = hr_patches + patches_dc hr_data = ImageUtilities.reconstruct_patches(hr_patches, resized_image.size, ImageUtilities.gaussian_filter()) resized_image.Y = hr_data return resized_image
def encode(img): """ An encoding function that gets a message from the user and converts each character in that message to an ascii value. It then takes a bunch of pixels from the image and sets the alpha value of each pixel to a corresponding value from our int list. """ msg = getInput(img) #Get User input ints = stringToInts(msg) #Convert all characters in the input to their ascii values ImageUtilities.setPixelAlphasFromIntsRandom(img, ints) #For every ascii value set a different pixel's alpha value to that ascii value. return img
def decode(img): """ A decoding function that gets all of the alpha values associated with all the pixels in our image which are somewhere between 0-255 and converts that alpha value to a character. """ ints = [] #A list of ints that will contain all of our alpha values. width, height = img.size #Get the width and the height of my image. size = width * height #The number of pixels in our image. position = 0 #The position we are in out list. percent = 0 #The percent of decoding we have done for our image. pixelData = ImageUtilities.getPixelList(img) #Get all of the pixels in the image and put them into a list. for y in range(height): #Iterate across the pixels from top to bottom. for x in range(width): #Iterate across out image from left to right. alpha = ImageUtilities.getAlphaFromList(img, pixelData, x, y) #Referenced the dumped contents if (alpha == 255): #If the alpha of our pixel is 255.... position += 1 #Increment our position value = int(size / 100) #Get a reference for what 1 percent in our image is. if (position % value == 0): #If we go up 1 percent... percent += 1 #Increment our percent value print("Decode progress: " + str(percent) + " of 100") #Print what percent we have gone through in our image. continue #I don't want 255 values because that means I reached the end of my message. ints.append(alpha) #Get the alpha value and append it to my list of ints. position += 1 #Increment the position variable by 1. value = int(size / 100) #Get a reference for what 1 percent in our image is. if (position % value == 0): #If we go up 1 percent... percent += 1 #Increment out percent value. print("Decode progress: " + str(percent) + " of 100") #Print what percent we have gone through in our image. msg = "" #Make an empty string to store our decoded message. for value in ints: #Iterate across my list of ints. (For each int in my list...) msg += chr(value) #Convert my int to it's character value and add it back to my message. return msg
def super_resolution(self, ratio): image = self.image examples_dataset = image.construct_dataset() super_resolutioned_image = image construct_level = int(math.log(ratio, self.alpha) + 0.5) for level in range(construct_level): super_resolutioned_image = self.super_resolution_dataset(super_resolutioned_image, self.alpha, examples_dataset) super_resolutioned_image = ImageUtilities.project_high2low(super_resolutioned_image, image, self.alpha, 3, level+1) new_examples_dataset = super_resolutioned_image.construct_dataset() examples_dataset.merge(new_examples_dataset) return super_resolutioned_image
def getInput(image): """ Get user input and make sure it isn't longer than the number of pixels in my image Params: image<Image>: The image to pass in to check it's size. """ length = ImageUtilities.getImageLength(image) message = input("Please input a message of: " + str(length) + " or less characters.") if (len(message) > length): print("Error, too many characters imput!") print("Expected: " + str(length) + " characters or less but got: " + str(len(message)) + " characters.") return return message
def setImage(self, image=None): print("Image set") self._pixmapItem.setPixmap(ImageUtilities.opencvImageToPixmap(image)) self._empty = False self.setDragMode(QtWidgets.QGraphicsView.NoDrag) # Show the image background container self._container.setVisible(True) self.rotateImage(0) # Set rotation origin in the center of the image pixmapSize = self._pixmapItem.pixmap().size() self._pixmapItem.setTransformOriginPoint(pixmapSize.width() // 2, pixmapSize.height() // 2) self.imageChanged()
lower_thres = 50 upper_thres = 150 red_edges = cv2.Canny(red_mask, lower_thres, upper_thres) blue_edges = cv2.Canny(blue_mask, lower_thres, upper_thres) yellow_edges = cv2.Canny(yellow_mask, lower_thres, upper_thres) black_edges = cv2.Canny(gray_feed, lower_thres, upper_thres) # Dilating the resulting edges # Dilating blue_edges = cv2.dilate(blue_edges, kernel, iterations=1) yellow_edges = cv2.dilate(yellow_edges, kernel, iterations=1) red_edges = cv2.dilate(red_edges, kernel, iterations=1) # Detecting the contours and displaying them. iu.getArrowContours(blue_edges, outputImg, 2000, "blue") iu.getArrowContours(red_edges, outputImg, 2000, "red") iu.getArrowContours(yellow_edges, outputImg, 2000, "yellow") iu.getBoxContours(red_edges, outputImg, 2000, "red") iu.getTriangleContours(red_edges, outputImg, 2000, "red") iu.getCrossContours(black_edges, outputImg, 2000, "Black") # Image stacking script that was open sourced imgStack = iu.stackImages( 0.5, ([feed, gray_feed, hsv], [red_mask, yellow_mask, blue_mask], [ red_edges, yellow_edges, blue_edges ], [black_edges, outputImg, outputImg])) # Displays the results cv2.imshow("Result", imgStack) cv2.imshow("Output", outputImg)
def execute(self, inData): print("Executing grayscale convertion stage") self._grayMatrix = ImageUtilities.rgb2grayNaive(inData) return self._grayMatrix
return msg #Return my message string. #Start the main CODE! Colors = Colors() #Initialize all of our colors. userInput = input("Would you like to encode(e) or decode(d) a message?") if (userInput == "e"): e_mode = input("Would you like to open(o) or create(c) a new image?") if (e_mode == "c"): image_name = input( "Please enter the name of the image you wish to create. Example) my_image.png" ) img = ImageUtilities.createPNGImage("RGBA", 60, 30, Colors.white) #Make a white image #Encode the image alpha values. img = encode(img) #Save and display the image. ImageUtilities.save(img, image_name) #Save the image if (e_mode == "o"): img_name = input( "Please enter the name of the image you wish to open. Example) my_image.png" ) img = Image.open(img_name) #Encode the image alpha values. img = encode(img)