igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] Fwd: convert an image into network


From: MikeS
Subject: [igraph] Fwd: convert an image into network
Date: Mon, 8 Feb 2016 22:21:10 +0600

Hello!

I am looking for a method in order to convert an image into a network.
I have found the study Z. Wu, X. Lu, Y. Deng, Image edge detection
based on local dimension: A complex networks approach. Physica A
(2015), http://dx.doi.org/10.1016/j.physa.2015.07.020

In this paper a model for mapping a grayscale image into weighted
undirected network is proposed. This model is based on the weighted
combination of the Euclidean distance and gray-level similarity
between pixels. In proposed model, pixels and relationships between
them in the image are respectively regarded as nodes and edges in the
network. The value of Euclidean distance of the two pixels defines
whether there is or not an edge between corresponding nodes. The
weight of corresponding edge defines by the balance compromise between
the Euclidean distance and the absolute value of gray-level similarity
of two pixels.

I would like to convert an image into network with the igraph.
Let’s take an image (4 by 4 pixels), 12 pixels are white and 4 pixel – black.

My current code is below:

n <- m <-4

img <- matrix(c(255,255,255,255, 255,255,255,255, 255,255,255,255,
0,0,0,0), nrow = n, ncol = m)

R <- 2
a <- 1
b <- 1

M <- t(img) # an grayscale image
C <- cbind(c(row(M)), c(col(M)))
D <- as.matrix(dist(C, method = "euclidean")) # Euclidean distance
E <- as.numeric(D <= R) # whether there is or not an edge between
corresponding nodes
G <- as.matrix(dist(matrix(M, ncol = 1), method = "manhattan")) #
absolute value of gray-level similarity
B <- E*(((a * G) ^ 2 + (b * D) ^ 2) ^ (1 / 2))
g <- graph.adjacency(B, weighted=TRUE, mode="undirected", diag=FALSE)

V(g)$name <- as.character(1:(n*m))

# create layout

cx <-rep(1:n, each = m)
cy <-rep(c(1:m), times = n)

mylayout<-as.matrix(cbind(cx, -cy))

plot(g, layout=mylayout,
          vertex.shape = "square",
          vertex.label = V(g)$name,
          edge.label=round(E(g)$weight, 1),
          edge.label.cex=.75,
          edge.curved = TRUE
     )

In the above code the binary value E defines whether there is or not
an edge between corresponding nodes. In this case a graph has the
constant topology (the number of nodes and edges) for any grayscale
images with equal sizes (n times m pixels).

Could anyone please give me an idea how to take into account the
gray-level similarity of pixels in order to mapping a grayscale image
into weighted undirected network?
--
MikeS



reply via email to

[Prev in Thread] Current Thread [Next in Thread]