Azzera filtri
Azzera filtri

data import from figure

3 visualizzazioni (ultimi 30 giorni)
niccolò guazzi
niccolò guazzi il 16 Apr 2019
Risposto: Walter Roberson il 16 Apr 2019
Dear all,
actually i'm tring to import data from an image .png in order to create a matrix to store them. I've seen the usage of imread function but what i obtained is a matrix 420x560x3 uint 8. I can't understand how to use it because what i would need is to enter in that matrix with an index i and j (for x axes and y axes) and read the value stored in it. Any opininon on how to proceed?
(If it would need of help i also downloaded the image toolbox).
Thanks,
NIccolò.

Risposta accettata

Walter Roberson
Walter Roberson il 16 Apr 2019
?? imread() already creates a matrix to store the information. The matrix returned by imread() is that matrix.
If you want to look at a particular x, y location in the matrix, then the sequence would look like
img = imread('YourFileNameGoesHere.png');
x_of_interest = 17;
y_of_interest = 83;
pixel_value_at_x_y = img(y_of_interest, x_of_interest, :);
Note that y is the row index, and that x is the column index.
Note that if you wanted to examine a number of individual pixels, then you would need a different solution:
x_of_interest = [17 17 184];
y_of_interest = [83 84 5];
[rows, columns, panes] = size(img);
ind = sub2ind([rows, columns], y_of_interest, x_of_interest);
pixel_value_at_x_y(:,1) = img(ind + 0*rows*columns);
pixel_value_at_x_y(:,2) = img(ind + 1*rows*columns);
pixel_value_at_x_y(:,3) = img(ind + 2*rows*columns);
then the first row would be the R then G then B components for x = 17, y = 83, and the second row would be RGB for x = 17, y = 84, and the third row would be RGB for x = 184, y = 5.
Or you could simply loop:
x_of_interest = [17 17 184];
y_of_interest = [83 84 5];
for K = 1 : length(x_of_interest)
pixel_value_at_x_y(K, :) = img(y_of_interest(K), x_of_interest(K), :);
end
The way I used with sub2ind() takes more understanding of how images are stored and how subscripts are calculated. Because looping is a lot clearer for most people, I would recommend using the loop unless you are extracting values at a lot of different locations.

Più risposte (0)

Categorie

Scopri di più su Images in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by