Skip to content

Instantly share code, notes, and snippets.

@christinapetris
Forked from dribnet/.block
Last active May 19, 2017 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christinapetris/ca58a32e757c6c84227ae481e4817a7a to your computer and use it in GitHub Desktop.
Save christinapetris/ca58a32e757c6c84227ae481e4817a7a to your computer and use it in GitHub Desktop.
17.1.MDDN242 PS3
license: mit
downloads
resized
colorgrid
smartgrid
customgrid
// note: this file is poorly named - it can generally be ignored.
// helper functions below for supporting blocks/purview
function saveBlocksImages(doZoom) {
if(doZoom == null) {
doZoom = false;
}
// generate 960x500 preview.jpg of entire canvas
// TODO: should this be recycled?
var offscreenCanvas = document.createElement('canvas');
offscreenCanvas.width = 960;
offscreenCanvas.height = 500;
var context = offscreenCanvas.getContext('2d');
// background is flat white
context.fillStyle="#FFFFFF";
context.fillRect(0, 0, 960, 500);
context.drawImage(this.canvas, 0, 0, 960, 500);
// save to browser
var downloadMime = 'image/octet-stream';
var imageData = offscreenCanvas.toDataURL('image/jpeg');
imageData = imageData.replace('image/jpeg', downloadMime);
p5.prototype.downloadFile(imageData, 'preview.jpg', 'jpg');
// generate 230x120 thumbnail.png centered on mouse
offscreenCanvas.width = 230;
offscreenCanvas.height = 120;
// background is flat white
context = offscreenCanvas.getContext('2d');
context.fillStyle="#FFFFFF";
context.fillRect(0, 0, 230, 120);
if(doZoom) {
// pixelDensity does the right thing on retina displays
var pd = this._pixelDensity;
var sx = pd * mouseX - pd * 230/2;
var sy = pd * mouseY - pd * 120/2;
var sw = pd * 230;
var sh = pd * 120;
// bounds checking - just displace if necessary
if (sx < 0) {
sx = 0;
}
if (sx > this.canvas.width - sw) {
sx = this.canvas.width - sw;
}
if (sy < 0) {
sy = 0;
}
if (sy > this.canvas.height - sh) {
sy = this.canvas.height - sh;
}
// save to browser
context.drawImage(this.canvas, sx, sy, sw, sh, 0, 0, 230, 120);
}
else {
// now scaledown
var full_width = this.canvas.width;
var full_height = this.canvas.height;
context.drawImage(this.canvas, 0, 0, full_width, full_height, 0, 0, 230, 120);
}
imageData = offscreenCanvas.toDataURL('image/png');
imageData = imageData.replace('image/png', downloadMime);
p5.prototype.downloadFile(imageData, 'thumbnail.png', 'png');
}

PS3 MDDN 242 2017

Final

In the beginning I scraped pokemon from trade me then I tried scraping off DeviantArt. Scraping off DeviantArt was a really slow process at first because I think that many of the same images were being downloaded again. To make it faster I looked at the DeviantArt url and saw it goes up in 24 increments so I made a for-loop in the script to do that too.

The pokemon experiments were nice but I thought they were a bit random. I wanted to have some more order in my montage and to flow nicer. So that's when I thought of scraping flowers because it is a more focused set of images. The colourgrid for this was really successful in my opinion with a really nice gradient of colour. The smartgrid was not as good, but still good because it was interesting how it categorised things such as having the sunset photos group, the close up photos group and smaller bunches of flowers group together.

For the next experiment, to create result 2, I scraped food. The reason I did this is because I wanted a data set which is still obvious, but also has a variety of shapes and colours. I think this was really successful in grouping the deserts away from the meals.

For the third result I wanted to experiment what a different layout would look like so I scraped landscape paintings. This was also really successful grouping the brighter, colourful images apart from the darker, duller images.

My final upload is an updated version of the customgrid version of the food scrape. Something to note further about the groupings is that it is quite interesting that the healthy foods group together, but there are also lollies which group near the berries which are not healthy. I think that the food scrape was the most successful because it has more obvious variety with a range of colours and as mentioned earlier it has successful groupings.

Throughout the project the main thing I payed attention to when manually filtering was to get rid of borders of images.

#!/bin/bash
# show commands and stop if there is an error
set -ex
# make the directory if it is not there
mkdir -p downloads
# clean the directory if there are old results
rm -f downloads/*
SEARCH_STRING="food"
# get 5 pages
# for PAGE in {1..5}
# do
#get 45x24 images
STEPSIZE=24
for OFFSET in {0..200}
do
OFFSET2=$(($OFFSET*$STEPSIZE))
#for 3 pages
#for PAGE in {1..3}
#do
# build the url #URL='http://www.trademe.co.nz/Browse/SearchResults.aspx?&cid=0&searchType=&searchString='$SEARCH_STRING'&x=0&y=0&type=Search&sort_order=&redirectFromAll=False&rptpath=all&page='$PAGE'&user_region=100&user_district=0&generalSearch_keypresses=8&generalSearch_suggested=0&generalSearch_suggestedCategory='
#for deviantart #for landscape paintings
# URL='http://www.deviantart.com/whats-hot/?q='$SEARCH_STRING'&offset='$OFFSET2''
#for flowers - I made the categories more specific
# URL='http://www.deviantart.com/photography/nature/flora/whats-hot/?q='$SEARCH_STRING'&offset='$OFFSET2''
#for food -
URL='http://www.deviantart.com/photography/still/whats-hot/?q='$SEARCH_STRING'&offset='$OFFSET2''
# fetch the images
wget --adjust-extension \
--random-wait \
--limit-rate=100k \
--span-hosts \
--convert-links \
--backup-converted \
--no-directories \
--timestamping \
--page-requisites \
--directory-prefix=downloads \
--execute robots=off \
--accept=[0-9]*.jpg,.png \
$URL
# other unused arguments
# --recursive \
# --level 1 \
# --domains en.wikipedia.org \
done
#!/bin/bash
if [ ! -d "/usr/local/anaconda/extras" ]; then
# Control will enter here if DIRECTORY doesn't exist.
echo "smartgrid program not found"
echo "please first install using directions on blackboard"
exit 1
fi
# show commands and stop if there is an error
set -ex
HOME="/usr/local/anaconda/extras/home"
export PATH="/usr/local/anaconda/bin:$PATH"
python /usr/local/anaconda/extras/smartgrid.py \
--tile 26x13 \
--input-glob 'resized/*' \
--left-image 'resized/1c30ea94ff73bccff16c6a05f7b5fda8.jpg' \
--right-image 'resized/066014b0707976da1d99d3428c28442d.jpg' \
--output-path customgrid
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css"></script>
<style>
body {padding: 0; margin: 0;}
#image-map {
width: 960;
height: 500;
border: 1px solid #ccc;
margin-bottom: 10px;
}
</style>
</head>
<body style="background-color:white">
<div id="image-map"></div>
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script language="javascript" type="text/javascript" src="zoom_image.js"></script>
<br>
<a href="montage.jpg">full size montage</a><br>
<a href="left_right.jpg">left right images</a><br>
<a href="tsne.png">tsne</a><br>
<a href="tsne_spun.png">tsne spun</a><br>
<a href="movement.png">movement</a><br>
</body>
#!/bin/bash
if [ -d "/usr/local/anaconda/extras" ]; then
# Control will enter here if DIRECTORY doesn't exist.
echo "smartgrid program already installed"
exit 1
fi
# show commands and stop if there is an error
set -ex
# make the directory if it is not there
mkdir -p /tmp/smartgrid
# clean the directory if there are old results
rm -f /tmp/smartgrid/*
cd /tmp/smartgrid
wget http://deeptom.staff.vuw.ac.nz:9000/smartgrid.tgz
cd /usr/local
tar xvfz /tmp/smartgrid/smartgrid.tgz
echo "DONE: smartgrid program installed"
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment