nearest-neighbor

How To Rotate Image By Nearest Neighbor Interpolation Using Matlab

空扰寡人 提交于 2019-11-28 09:12:42
My Plain Code without interpolation: im1 = imread('lena.jpg');imshow(im1); [m,n,p]=size(im1); thet = rand(1); m1=m*cos(thet)+n*sin(thet); n1=m*sin(thet)+n*cos(thet); for i=1:m for j=1:n t = uint16((i-m/2)*cos(thet)-(j-n/2)*sin(thet)+m1/2); s = uint16((i-m/2)*sin(thet)+(j-n/2)*cos(thet)+n1/2); if t~=0 && s~=0 im2(t,s,:)=im1(i,j,:); end end end figure; imshow(im2); This code creates black spot, the problem is how to do interpolation? Thank you all for any illumination. P.S. Not asking for build-in function: imrotate(im1,1/thet,'nearest'); To rotate the image without the black spots, you need to

Suitable choice of data structure and algorithm for fast k-Nearest Neighbor search in 2D

天涯浪子 提交于 2019-11-28 07:37:34
I have a dataset of approximately 100,000 (X, Y) pairs representing points in 2D space. For each point, I want to find its k-nearest neighbors. So, my question is - what data-structure / algorithm would be a suitable choice, assuming I want to absolutely minimise the overall running time? I'm not looking for code - just a pointer towards a suitable approach. I'm a bit daunted by the range of choices that seem relevent - quad-trees, R-trees, kd-trees, etc. I'm thinking the best approach is to build a data structure, then run some kind of k-Nearest Neighbor search for each point. However, since

How to find the previous and next record using a single query in MySQL?

ぐ巨炮叔叔 提交于 2019-11-28 00:17:29
问题 I have a database, and I want to find out the previous and next record ordered by ID, using a single query. I tried to do a union but that does not work. :( SELECT * FROM table WHERE `id` > 1556 LIMIT 1 UNION SELECT * FROM table WHERE `id` <1556 ORDER BY `product_id` LIMIT 1 Any ideas? Thanks a lot. 回答1: You need to change up your ORDER BY : SELECT * FROM table WHERE `id` > 1556 ORDER BY `id` ASC LIMIT 1 UNION SELECT * FROM table WHERE `id` < 1556 ORDER BY `id` DESC LIMIT 1 This ensures that

All k nearest neighbors in 2D, C++

僤鯓⒐⒋嵵緔 提交于 2019-11-27 21:39:38
I need to find for each point of the data set all its nearest neighbors. The data set contains approx. 10 million 2D points. The data are close to the grid, but do not form a precise grid... This option excludes (in my opinion) the use of KD Trees, where the basic assumption is no points have same x coordinate and y coordinate. I need a fast algorithm O(n) or better (but not too difficult for implementation :-)) ) to solve this problem ... Due to the fact that boost is not standardized, I do not want to use it ... Thanks for your answers or code samples... I would do the following: Create a

Pixel neighbors in 2d array (image) using Python

廉价感情. 提交于 2019-11-27 20:13:05
I have a numpy array like this: x = np.array([[1,2,3],[4,5,6],[7,8,9]]) I need to create a function let's call it "neighbors" with the following input parameter: x: a numpy 2d array (i,j): the index of an element in a 2d array d: neighborhood radius As output I want to get the neighbors of the cell i,j with a given distance d . So if I run neighbors(im, i, j, d=1) with i = 1 and j = 1 (element value = 5) I should get the indices of the following values: [1,2,3,4,6,7,8,9] . I hope I make it clear. Is there any library like scipy which deal with this? I've done something working but it's a rough

Comparison of the runtime of Nearest Neighbor queries on different data structures

给你一囗甜甜゛ 提交于 2019-11-27 16:23:34
Given n points in d-dimensional space, there are several data structures, such as Kd-Trees, Quadtrees, etc. to index the points. On these data structures it is possible to implement straight-forward algorithm for nearest neighbor queries around a given input point. Is there a book, paper, survey, ... that compares the theoretical (mostly expected) runtime of the nearest neighbor query on different data structures? The data I am looking at is composed of fairly small point clouds, so it can all be processed in main memory. For the sake of simplicity, I assume the data to be uniformly

Nearest Neighbor Searching using Voronoi Diagrams

早过忘川 提交于 2019-11-27 16:13:39
问题 I've successfully implemented a way to generate Voronoi diagrams in 2 dimensions using Fortune's method. But now I'm trying to use it for nearest neighbor queries for a point (which is not one of the original points used to generate the diagram). I keep seeing people saying that it can be done in O(lg n) time (and I believe them), but I can't find a description of how it's actually done. I'm familiar with binary searches, but I can't figure out a good criteria to guarantee that upper bound. I

K-Nearest Neighbor Query in PostGIS

余生颓废 提交于 2019-11-27 16:13:03
问题 I am using the following Nearest Neighbor Query in PostGIS : SELECT g1.gid g2.gid FROM points as g1, polygons g2 WHERE g1.gid <> g2.gid ORDER BY g1.gid, ST_Distance(g1.the_geom,g2.the_geom) LIMIT k; Now, that I have created indexes on the_geom as well as gid column on both the tables, this query is taking much more time than other spatial queries involving spatial joins b/w two tables. Is there any better way to find K-nearest neighbors? I am using PostGIS. And, another query which is taking

Distance of point feature to nearest polygon in R

只谈情不闲聊 提交于 2019-11-27 12:34:24
问题 I working on a project at the moment, where I have a point feature -- the point feature includes a 142 points -- and multiple polygon (around 10). I want to calculate the distance between every single point and the nearest polygon feature in R. My current approach is tedious and a bit long winded. I am currently planning to calculate the distance between every single point and every single polygon. For example, I would calculate the distance between the 142 points and Polygon A, the distance

Confusion in hashing used by LSH

不问归期 提交于 2019-11-27 08:37:23
问题 Matrix M is the signatures matrix, which is produced via Minhashing of the actual data, has documents as columns and words as rows. So a column represents a document. Now it says that every stripe ( b in number, r in length) has its columns hashed, so that a column falls in a bucket. If two columns fall in the same bucket, for >= 1 stripes, then they are potentially similar. So that means that I should create b hashtables and find b independent hash functions? Or just one is enough and every