Regarding importing JPEG image - gis

I have a scaned JPEG image of a location with path ways,building and play grounds but without any digitized data. It is a simple drawing on paper as a thought process of an area. So, I want to import this image as a environment and to move agents on it according to pacth colors. Like if road gray color, if gorund green color, if water blue color and so on.
I have gone through the dictionary, and available web links but still unable to do. I imported the image but finding difficult with patches. I tried to convert it into vector format which is .svg and then to .png to import but the patch coordinate value and patch color when i inspect are confusing.
Now i am trying to digitize it using a GIS software QGIS, to make it ascii. Let's see. Please help me out where i am lacking.
I am sorry for the vagueness of my question. Above is the image, i created in paint. I am able to import the image with
import-drawing "map.png"
import-pcolors "map.png"
but i am unable to ask agents to move only on the patches with pcolor = gray (assumed as road of the map). with the below code i asked to stay on the area with green color.
to setup
clear-all
import-drawing "map.png"
import-pcolors "map.png"
create-turtles 5[
set xcor -21
set ycor -2
set color red
set shape "person"
set size 0.5
]
end
to go
ask turtles [ fd 1 if pcolor != 64.3 [ set heading heading - 180]]
end
Hope now i am able to make understand.

Use the primitive import-pcolors it can accept most picture formats.
Here is a scheme that I have found useful
if my drawing is clearly and evenly colored I use import-pcolors it takes BMP, JPG, GIF, and PNG. You can also do it from the Menu File
if it is not I use import-pcolors-rgb and use code that looks a bit like this to tease out the regions I want.
ask patches
[
if item 0 pcolor > RA and item 1 pcolor < RB and item 2 pcolor < RC
[set pcolor rgb 255 0 0]
.
.
.
]
then I make RA RB RC etc etc sliders and tweak them until I have the regions I want.
The easiest of course is to use distinct solid colors.
Ask one of the grey patches what color it is use that number instead of 64.3

Related

Turtles with size in Netlogo

I need to create turtles that have a certain dimension and check for overlap.
Since turtles per definition have no extension, I thought maybe the gis extension could be useful.
There is a way of associating an envelope with a turtle like
let gis:envelope-of self (list (xcor - 2 ) (xcor + 2) (ycor - 2) (ycor + 2))
But I don't know how to use this to draw the envelope and to check for overlaps.
Another way could be to give up the idea of one turtle having dimensions and to create a gis dataset from turtles by using
gis:turtle-dataset turtle-set
But I don't know how to create a polygon with this :-(
Any ideas?
Updated for Seth's comment to make explicit the different approaches for circles and others.
If the turtles are circles, then there is an overlap if the sum of the sizes of the two turtles < distance between them / 2, using the distance primitive as in Seth's comment.
However, if you have squares or other shapes, then you will have to do some fancy stuff with heading and the various trigonometry functions, and will need the differences of positions in the x and y direction (differences in xcor and ycor respectively. Something like this will get you started:
to-report xdiff [ turt1 turt2 ]
report [xcor] of turt1 - [xcor] of turt2
end
In the end I took an easy way out:
Since my objects don't have to move, I use adjacent patches to form a block of the needed size. Before I occupy a new patch, I check if it is already used and if so I delete all newly occupied patches.
Not very versatily, but it does the job for me so far.

Targa image – damaged red and green channels

I've a problem with 16-bit targa file. I'm opening image and it colors are weird. It's problem with red and green channels – blue is fine.
How I can repair targa image, to look like on example? (first is original image, second is as must look.)
Image
EDIT: this answer gives results that look right, but won't be bit-identical to the original. Something weirder is going on.
You can make your corrupted image out of your original image by subjecting the red and green channels to a function that doubles the value, subject to wraparound:
F(r) = (r*2) % 255
F(g) = (g*2) % 255
These functions are not invertible, because more than one input value can map to the same output value. In particular,
F^-1(r) = {r / 2, r / 2 + 128}
But we can still try to recover the image if we're willing to tolerate some errors. We'll try to guess whether red (or green) should be high; if so, add 128.
Two pieces of information can guide our guess:
Is the blue channel high? Unless images contain strongly blue pixels, this is a hint that the red and green channels should be high, too.
Is there an adjacent pixel whose red (or green) channel is high, while this pixel's red channel is very low (say, less than 64)? This may suggest that both pixels are relatively bright, but this pixel's red channel got wrapped.
I recovered something very close to your original image using just the blue channel information to decide between r / 2 and r / 2 + 128, though it would probably be better using the neighboring pixels' red and green channels as well.
As a side note, one way this sort of problem could occur is if there were originally (say) 6 bits of red information, but only the least significant 5 bits were retained when the file was written. It would be useful to look at how these images were acquired to make sure that you're not chopping off the most significant bits of your R and G channels somehow.

Who knows, or knows how to figure out, which google map markers are available?

I want to use a variety of location markers in a map, of different colors. I like google's "teardrop"-shaped ones so that the location itself is less obscured, due to the point top of the inverted teardrop.
This is a link to the green one:
http://www.googlemapsmarkers.com/v1/009900/
...and the green uses 0099FF
But what about the other colors? Is there a list somewhere or do I have to write a utility to convert color to RGB, or what?
Even with that, how would I know which colors are supported/supplied? Or are the colors dynamically generated based on the RGB value you pass?
UPDATE
Based on the chart here:
http://cloford.com/resources/colours/500col.htm
...I would expect that entering this:
http://www.googlemapsmarkers.com/v1/65535/
...would return a bright yellow marker, but instead I get:
"400. That’s an error.
Your client has issued a malformed or illegal request.
The parameter 'chs' must have a width of at least 1 pixel.
That’s all we know."
UPDATE 2
I also found that you can put text on the marker by inserting the text in the penultimate spot.
This returns a blank yellow inverted teardrop:
http://www.googlemapsmarkers.com/v1/FFFF00/
..and this:
http://www.googlemapsmarkers.com/v1/Platypus/FFFF00/
...returns an inverted yellow teardrop with the word "Platypus" plastered on top of it.
You can pass your own RGB color. I suppose the markers are dynamically generated when the server receive your request, but anyway, you can create the color you exactly want.

pygame: How would I shade/blit a non-rectangular section of an image?

So I know how to shade an image. And I know how to blit a rectangular section of an image. But what about, say, a triangle? Or a trapezoid? (e.g. http://i.imgur.com/Gtwhs.png)
A minute after I asked this, I figured out how to shade, at least. Isn't that always the way?
Anyway, it basically comes down to something as simple as:
surface.blit(image, pos, area)
pygame.draw.polygon(surface, (0,0,0,128), pointlist, 0)
where 128 is whatever alpha value you want and pointlist is a list of the vertices around the section you want.

Finding close colors of a given color

I´d like to know, how, through actionscript 3, to get an array of ARGB (hexadecimal) colors, that is close to a given color.
Example:
0xFF00FF00
A green.
How to get variations of green?
I´m trying to get some green colors of a bitmapdata.
I´ve tried to get it by making a loop getting the colors using getPixels32.
The problem is, I think the bits colors of each position are different from the bits of the bitmap rendered.
It´s for a pathfinder.
Each green bit sets a node in a map, as walkable.
So I need to know what are these colors to set it as walkable for the pathfinder.
Any suggestions?
RGB space is terrible for interpreting whether colors are similar to one another. A different color space that matches closer to human perception of color is HSV (hue saturation and value). Here are the steps you should follow:
Convert your value from RGB space to HSV (http://www.cs.rit.edu/~ncs/color/t_convert.html)
Modify the saturation and value to obtain different shades of the same green hue.
You can even modify the hue a little with a defined tolerance level you specify
Reconvert back to HSV to RGB
I believe technically..one color space is smaller than the other, meaning it is not always a 1:1 conversion - but it should serve your purpose.