How to express coordinate range of an area

I want to read the pixel value of an area but I dont know how to write the coordinate range
x = [ 1119 until 1121]
y = [ 392 until 394]
I have to change the 'until' word into what symbol?

Respuestas (1)

Johannes Fischer
Johannes Fischer el 23 de Sept. de 2019
You are looking for the colon operator (https://www.mathworks.com/help/matlab/ref/colon.html)
x = 1119:1121;
y = 392:394;

6 comentarios

the coding just read the pixel value of (1119,392),(1120,393) and (1121,394).
the pixel value for the whole area did not appear.
my current coding is:
RGB = imread('aligner crop.jpg');
x = [1119:1121];
y = [392:394];
pixels = impixel(RGB,x,y)
With impixel, you specify each pixels coordinates, so in this case you would need to use
x = [1119 1119 1119 1120 1120 1120 1121 1121 1121];
y = [392 393 394 392 393 394 392 393 394];
You seem to be interested in the RGB values in these pixels. Then I would recommend using
x = [1119:1121];
y = [392:394];
pixels = RGB(x, y, :);
I have tried the coding but it is error on the line of
pixels = RGB(x, y, :);
Steven Lord
Steven Lord el 23 de Sept. de 2019
What is the full and exact text of the error message you received when you tried running that line of code? Show us all the text displayed in red (and all the text displayed in orange if you receive any warning messages.)
That error message means you are trying to get data points from a pixel that doesnt exist. Along the first dimension, your image has 825 pixels. with
x = [1119:1121];
you are trying to access data that does not exist, hence the error.
In order to see how big your image is, use
size(RGB)
It will give you the number of pixels along each dimension.

Iniciar sesión para comentar.

Etiquetas

Comentada:

el 24 de Sept. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by