I know this is not much of a question but a seek of help, but I wanted to give it a shot too since I'm really blocked with this.
I want to create a sort of map (representend by a string) that is filled with numbers in a way similar to this example:
000000000000000000
001111000000011000
011111100000111110
000111110001111100
000011000000011000
000000000000000000
So the idea is that 0 would be like "nothing" or imagine this is a world map and 0s are grass tiles while 1s could be for example ground tiles.
I want to be able to generate something like that (on a bigger scale) with lots of small and big patches of "ground". But obviously it can't just be random 1s and 0s everywhere as it wouldn't look natural, it has to be somewhat natural looking shapes.
My maths are just too bad to think of a way to achieve this out of my head,
I'm not asking for the code, just seeking some help.
If you guys could point me in the right direction it would help a lot :)
Do you just want to generate this for fun, you might be looking for ascii art generator. There are lot of online tools available, just a search away for the phrase ascii art generator.
Background: Every image is made up of pixels. Every one of these pixels have a color defined by (R,G,B) with each component ranging from 0-255.
Defined Problem: You want to convert each pixel of an image to 0 or 1 based on their color. Color would be the defining attribute here as we expect the 0 attribute and 1 attribute to be visually different.
Solution: You'll need to create a function which will map each pixel of an image based on their RGB values to either 0 or 1. You'll have to classify ranges for them according to which every pixel will either be converted to a 0 or 1 as per their weight.
Implementation: I'll probably be looking towards Python Libraries. There are tons of them and I'm certain there must be one to access an image at a bit level. When you have the number of pixels in length and width, use those parameters to construct an array of that size and loop your function over the image pixels and go on filling the results in the array.
Crude Way: You can alternatively visit this website which will do it for you. Just in case you want it done at the easiest way possible: https://www.text-image.com/convert/
There are many more like this if you search for them.
If you want an algorithm you could probably start with all 0s. Then randomly and sparsely place some 1s into the field. Now take each of the placed 1s and randomly select a direction (up, down, left, right) and a number n of steps between 0 and a small number m, e.g. 3. Let the selected 1 "grow" in that direction n times. i.e. cover the n spots in that direction with 1s. Repeat for any newly placed 1s (maybe omit those which were already placed over previously existing 1s) until no newly placed 1 is unprocessed. That should at least give you some "connected patches", maybe similar to plants e.g. grass might spread. And maybe play with m a little, to vary the size of the "patches".
I found what I was looking for,
I'll do it with Perlin Noise :)
Related
There was a gif on the internet where someone used some sort of CAD and drew multiple vector pictures in it. On the first frame they zoom-in on a tiny dot, revealing there a whole new different vector picture just on a different scale, and then they proceed to zoom-in further on another tiny dot, revealing another detailed picture, repeating several times. here is the link to the gif
Or another similar example: imagine you have a time-series with a granularity of a millisecond per sample and you zoom out to reveal years-worth of data.
My questions are: how such a fine-detailed data, in the end, gets rendered, when a huge amount of data ends up getting aliased into a single pixel.
Do you have to go through the whole dataset to render that pixel (i.e. in case of time-series: go through million records to just average them out into 1 line or in case of CAD render whole vector picture and blur it into tiny dot), or there are certain level-of-detail optimizations that can be applied so that you don't have to do this?
If so, how do they work and where one can learn about it?
This is a very well known problem in games development. In the following I am assuming you are using a scene graph, a node-based tree of objects.
Typical solutions involve a mix of these techniques:
Level Of Detail (LOD): multiple resolutions of the same model, which are shown or hidden so that only one is "visible" at any time. When to hide and show is usually determined by the distance between camera and object, but you could also include the scale of the object as a factor. Modern 3d/CAD software will sometimes offer you automatic "simplification" of models, which can be used as the low res LOD models.
At the lowest level, you could even just use the object's bounding
box. Checking whether a bounding box is in view is only around 1-7 point checks depending on how you check. And you can utilise object parenting for transitive bounding boxes.
Clipping: if a polygon is not rendered in the view port at all, no need to render it. In the GIF you posted, when the camera zooms in on a new scene, what is left from the larger model is a single polygon in the background.
Re-scaling of world coordinates: as you zoom in, the coordinates for vertices become sub-zero floating point numbers. Given you want all coordinates as precise as possible and given modern CPUs can only handle floats with 64 bits precision (and often use only 32 for better performance), it's a good idea to reset the scaling of the visible objects. What I mean by that is that as your camera zooms in to say 1/1000 of the previous view, you can scale up the bigger objects by a factor of 1000, and at the same time adjust the camera position and focal length. Any newly attached small model would use its original scale, thus preserving its precision.
This transition would be invisible to the viewer, but allows you to stay within well-defined 3d coordinates while being able to zoom in infinitely.
On a higher level: As you zoom into something and the camera gets closer to an object, it appears as if the world grows bigger relative to the view. While normally the camera space is moving and the world gets multiplied by the camera's matrix, the same effect can be achieved by changing the world coordinates instead of the camera.
First, you can use caching. With tiles, like it's done in cartography. You'll still need to go over all the points, but after that you'll be able zoom-in/zoom-out quite rapidly.
But if you don't have extra memory for cache (not so much actually, much less than the data itself), or don't have time to go over all the points you can use probabilistic approach.
It can be as simple as peeking only every other point (or every 10th point or whatever suits you). It yields decent results for some data. Again in cartography it works quite well for shorelines, but not so well for houses or administrative boarders - anything with a lot of straight lines.
Or you can take a more hardcore probabilistic approach: randomly peek some points, and if, for example, there're 100 data points that hit pixel one and only 50 hit pixel two, then you can more or less safely assume that if you'll continue to peek points still pixel one will be twice as likely to be hit that pixel two. So you can just give up and draw pixel one with a twice more heavy color.
Also consider how much data you can and want to put in a pixel. If you'll draw a pixel in black and white, then there're only 256 variants of color. And you don't need to be more precise. Or if you're going to draw a pixel in full color then you still need to ask yourself: will anyone notice the difference between something like rgb(123,12,54) and rgb(123,11,54)?
I have the following equation, which I try to implement. The upcoming question is not necessarily about this equation, but more generally, on how to deal with divisions by zero in image processing:
Here, I is an image, W is the difference between the image and its denoised version (so, W expresses the noise in the image), and K is an estimated fingerprint, gained from d images of the same camera. All calculations are done pixel-wise; so the equations does not involve a matrix multiplication. For more on the Idea of estimating digital fingerprints consult corresponding literature like the general wikipedia article or scientific papers.
However my problem arises when an Image has a pixel with value Zero, e.g. perfect black (let's say we only have one image, k=1, so the Zero gets not overwritten by the pixel value of the next image by chance, if the next pixelvalue is unequal Zero). Then I have a division by zero, which apparently is not defined.
How can I overcome this problem? One option I came up with was adding +1 to all pixels right before I even start the calculations. However this shifts the range of pixel values from [0|255] to [1|256], which then makes it impossible to work with data type uint8.
Other authors in papers I read on this topic, often do not consider values close the range borders. For example they only calculate the equation for pixelvalues [5|250]. They reason this, not because of the numerical problem but they say, if an image is totally saturated, or totally black, the fingerprint can not even be estimated properly in that area.
But again, my main concern is not about how this algorithm performs best, but rather in general: How to deal with divisions by 0 in image processing?
One solution is to use subtraction instead of division; however subtraction is not scale invariant it is translation invariant.
[e.g. the ratio will always be a normalized value between 0 and 1 ; and if it exceeds 1 you can reverse it; you can have the same normalization in subtraction but you need to find the max values attained by the variables]
Eventualy you will have to deal with division. Dividing a black image with itself is a proper subject - you can translate the values to some other range then transform back.
However 5/8 is not the same as 55/58. So you can take this only in a relativistic way. If you want to know the exact ratios you better stick with the original interval - and handle those as special cases. e.g if denom==0 do something with it; if num==0 and denom==0 0/0 that means we have an identity - it is exactly as if we had 1/1.
In PRNU and Fingerprint estimation, if you check the matlab implementation in Jessica Fridrich's webpage, they basically create a mask to get rid of saturated and low intensity pixels as you mentioned. Then they convert Image matrix to single(I) which makes the image 32 bit floating point. Add 1 to the image and divide.
To your general question, in image processing, I like to create mask and add one to only zero valued pixel values.
img=imread('my gray img');
a_mat=rand(size(img));
mask=uint8(img==0);
div= a_mat/(img+mask);
This will prevent division by zero error. (Not tested but it should work)
Let's assume two similar timeseries like below. Both are similar and never equal. E.g. the length can be different and similar parts can be between non-similar parts. I've tried to indicate the similarity by black arrows.
I'm not a mathematician and so I'm questioning if is there an approximately (or perfect) fast way to find a mapping table between them? I've digged into dynamic time warping but at this point I'm thinking that dtw is not what I'm looking for (not sure).
The mapping table good be like
Sequence Location_Timeseries_0 Location_Timeseries_1 Length
0 LTO_0 LT1_0 N
1 LTO_1 LT1_1 M
...
Can someone put me into the right direction?
Based on what you say/show, DTW is perfect
See the bottom right of http://www.cs.ucr.edu/~eamonn/sampleslides2.jpg
or the right of http://www.cs.ucr.edu/~eamonn/sampleslides3.jpg
So I want to compare one 2-dimensional array with another 2-dimensional array (acctually portion of another larger 2-dimensional arrays). What I need to do is to compare the first array with the second, but I also need to compare it from multiple angles, rotating one of them if you will.
I'm writing this in c++ and I'm using vectors (in case there is a specific algorithm or function for these that would help)
Here's an example of what I need to be able to do with this:
Take this map:
0001000
0001000
0001000
0001111
0000000
Compare it to this (which means if 1 is road and 0 is grass, this would help
me find 'turns' in the road):
010
110
000
Comparing it like that won't yield any results, BUT, if I rotate it to 180
degrees:
010
011
000
It fits.
More specifally I will compare a whole bunch of small arrays to the large array. I will not compare every location on the large array, only pick a location at random and a small array at random, rotate the small array to all 4 sides and see if they match. I will repeat this a few hundred times to find a decent sample of locations where a random selected sample of small maps compare positively to the large map.
Basically... :)
Atm I'm trying to figure it out, but I don't want to reinvent a wheel if I can help it.
(UPDATE: Close to solving this! I realised that I acctually need to rotate the lesser grid 8 times, I need to match every mirror!
UPDATE2: lol I solved it wtf. Will post as soon as I understand what the code acctually does, might as well. 5 AM I'm crazy like this!)
Lol. Interesting problem. I want to try it too. Try reading into rotation matrices. They're a little straightforward when it comes to rotating the entire matrices, and if the angle of rotation greatly concerns you.
http://en.wikipedia.org/wiki/Rotation_matrix
I'm writing a program that works with images and at some point I need to posterize the image. This means I need to bin the colors, but I'm having trouble deciding how to tell how close one color is to another.
Given a color in RGB, I can think of at least 2 ways to see how different they are:
|r1 - r2| + |g1 - g2| + |b1 - b2|
sqrt((r1 - r2)^2 + (g1 - g2)^2 + (b1 - b2)^2)
And if I move into HSV, I can think of other ways of doing it.
So I ask, ignoring speed, what is the best way to tell how similar two colors are? Best meaning most accurate to the human eye.
Well, if speed is not an issue, the most accurate way would be to take some sample images and apply the filter to them using various cutoff values for the distance (distance being determined by one of the equations on the Color_difference page that astander linked to, meaning you'd have to use one of those color spaces listed there with the calculations, then convert to sRGB or something [which also means that you'd need to convert the image into the other color space first if it's not in it to begin with]), and then have a large number of people examine the images to see what looks best to them, then go with the cutoff value for the images that the majority agrees looks best.
Basically, it's largely a matter of subjectiveness; in fact, it also depends on how stylized you want the images, and you might even want to add in some sort of control so that you can alter the cutoff distance on the fly.
If speed does become a bit of an issue and/or you want more simplicity, then just use your second choice for distance calculation (which is simply the CIE76 equation; just make sure to use the Lab* color space) with the cutoff being around 2 or 2.3.
What do you mean by "posterize the image"?
If you're trying to cluster the colors into bins, you should look at
cluster analysis
Just a comment if you are going to move to HSV (or similar spaces):
Diffing on H: difference between 0° and 359° is numerically big but perceptually is negligible.
H difference if V or S are small - is small.
For computer vision apps, more important not perceptual difference (used mostly by paint manufacturers) but are these colors belong to the same object/segment or not. Which means that we might partially ignore V, which can change from lighting conditions.