def createAndApplyMask(imgName, upLeft, bottomRight): img = cv2.imread(start + "klase/cat/" + imgName) # učitavanja originalne slike mask = np.zeros(img.shape, dtype="uint8") # kreiranje crne slike (maske) cv2.rectangle(mask, upLeft, bottomRight, (255, 255, 255), -1) # crtanje bijelog popunjenog pravougaonika na maski maskedImg = useMask(img, mask) # primijeni masku na sliku path = start + 'maske' saveImage(maskedImg, path, imgName)
def setNASAPOTD(date=None): #getting image url #getting timestamp to save as imagename if date is not None: contents = request.urlopen( "https://api.nasa.gov/planetary/apod?date=" + date + "&api_key=" + nasa_api_key).read() timestamp = date else: contents = request.urlopen( "https://api.nasa.gov/planetary/apod?api_key=" + nasa_api_key).read() timestamp = save_image.getTimeStamp() response = json.loads(contents) imageurl = response['url'] print(imageurl) completename = save_image.saveImage(imageurl, timestamp=timestamp) setWall(completename)
def setBingPOTD(): #getting image url contents = request.urlopen( "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US" ).read() msg = json.loads(contents) images = msg['images'] images = images[0] data = images['url'] print(data) #checking if the url contains a image and if present setting it as wall pattern = re.compile(r'jpg') if (bool(re.search(pattern, data))): print("image found") base = "http://www.bing.com" downurl = base + data completename = save_image.saveImage(downurl) #setting wallpaer setWall(completename)
import praw import save_image import requests import os earthpornURL = "https://www.reddit.com/r/earthporn.json" secret = "fDLs_DEOnKeYCKP5n3jJ_n5b474" id = "sDHrovagvROA8w" redirect = "http://webxstudio.in" client_auth = requests.auth.HTTPBasicAuth( id , secret ) userAgent = "WallpaperBot by ganesh" reddit = praw.Reddit(client_id = id, client_secret = secret, user_agent = userAgent) def setWall(completename): os.system("/usr/bin/gsettings set org.gnome.desktop.background picture-uri "+completename) for listing in reddit.subreddit('earthporn').new(limit=1): completename = save_image.saveImage(listing.url) setWall(completename)
from PIL import Image import random import cv2 from path import start path_cat = start + 'dataset' valid_images = [".jpg", ".jpeg"] image_list = [] for f in os.listdir(path_cat): name = os.path.splitext(f)[0] ext = os.path.splitext(f)[1] if ext.lower() not in valid_images: continue image = Image.open(os.path.join(path_cat, f)) image_list.append((image, name)) random.shuffle(image_list) train_data, test_data = train_test_split(image_list, test_size=0.2) for img in train_data: newpath = start + 'train' saveImage(cv2.cvtColor(np.array(img[0]), cv2.COLOR_BGR2RGB), newpath, img[1] + ".jpg") for img in test_data: newpath = start + 'test' saveImage(cv2.cvtColor(np.array(img[0]), cv2.COLOR_BGR2RGB), newpath, img[1] + ".jpg")
import cv2 import os import numpy as np from PIL import Image from save_image import saveImage from path import start def denoiseRemoval(image): return cv2.medianBlur(image, 3) #iskoristen mediana filter za otklanjanje šuma path = start + 'dataset' valid_images = [".jpg", ".jpeg"] br = 1 for f in os.listdir(path): ext = os.path.splitext(f)[1] if ext.lower() not in valid_images: continue image = Image.open(os.path.join(path, f)) image = np.array(image) processed_image = denoiseRemoval(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) newpath = start + 'uklanjanje_suma' saveImage(processed_image, newpath, str(br) + ext.lower()) br += 1
def createDescriptor(image): image = resizeimage.resize_cover(image, [100, 100]) gray = cv2.cvtColor(np.array(image), cv2.COLOR_BGR2GRAY) fd, hog_image = hog(gray, orientations=8, pixels_per_cell=(16, 16), cells_per_block=(4, 4), block_norm='L2', visualize=True) return fd, hog_image hog_images = [] hog_features = [] path = start + 'poboljsane_slike' valid_images = [".jpg", ".jpeg"] br = 1 newpath = start + 'deskriptor' for f in os.listdir(path): ext = os.path.splitext(f)[1] if ext.lower() not in valid_images: continue image = Image.open(os.path.join(path, f)) fd, hog_image = createDescriptor(image) hog_images.append(hog_image) hog_features.append(fd) saveImage(hog_image, newpath, str(br) + ext.lower()) br += 1
while currenpost <= numposts: for submission in subreddit.hot( limit=25): #Searches through the first 25 posts first url = submission.url fileName = str(submission) fullPath = filePath + fileName + '.png' title = '"' + str(submission.title) + '"' credit = '(Via: u/' + str(submission.author) + ' on Reddit)' caption = title + '\n' + '\n' + credit + '\n' + '\n' + '\n' + hashtags if (url.endswith("jpg") or url.endswith("png")) and ( not url in urlPosted): #Post bounds can be set here try: urlPosted.append(url) save_image.saveImage(url, filePath, fileName, currenpost) save_image.correctShape(fullPath, fileName, filePath, currenpost) finalImgPath = fileName + str(currenpost) + 'final.jpg' fullFinalImgPath = filePath + finalImgPath instagram_script.uploadtoig(fullPath=fullFinalImgPath, caption=caption, post=post) subreddit = credentials.reddit.subreddit( '') #Subreddit name; refresh reddit currenpost = currenpost + 1 except: print("cant be posted, next...") continue
from brightness import changeBrightness from histogram import histogramEq import os from path import start import numpy as np from PIL import Image, ImageEnhance import cv2 from save_image import saveImage path = start + 'maske' valid_images = [".jpg", ".jpeg"] br = 1 path1 = start + 'cropped_masks' def poboljsaj(img): nova = changeBrightness(img) return histogramEq(cv2.cvtColor(np.array(nova), cv2.COLOR_BGR2RGB)) for f in os.listdir(path1): ext = os.path.splitext(f)[1] if ext.lower() not in valid_images: continue image = Image.open(os.path.join(path1, f)) new_image = poboljsaj(image) newpath = start + 'poboljsane_slike' saveImage(np.array(new_image), newpath, str(br) + ext.lower()) br += 1
import os import numpy as np from PIL import Image from path import start from save_image import saveImage def unsharpMasking(image): gaussian = cv2.GaussianBlur(image, (9, 9), 10.0) return cv2.addWeighted( image, 1.5, gaussian, -0.5, 0, image ) #konacna = image(original)*1.5 - gaussian(zamucena)*0.5 + 0; k=0.5 path = start + 'uklanjanje_suma' valid_images = [".jpg", ".jpeg"] br = 1 k = 1 for f in os.listdir(path): ext = os.path.splitext(f)[1] if ext.lower() not in valid_images: continue image = np.array(Image.open(os.path.join(path, f))) unsharp_image = unsharpMasking(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) newpath = start + 'maskiranje_neostrina' saveImage(unsharp_image, newpath, str(br) + ext.lower()) br += 1