Finding row and column number of values in an image matrix

11 views (last 30 days)
Hi all,
As the picture attached, on line 39, I am trying to use Find to return row and column numbers of a selected area in the image matrix.
However, it returns Col_r and Row_r with unexpected numbers of values (more than 500k values).
I am not sure whether I use the appropriate function to obtain the row and column numbers of values in the image matrix.
Could you please help provide some suggestion for me. Thank you so much.
  3 Comments
Chutiphon Moranon
Chutiphon Moranon on 3 Feb 2022
Thanks for your reply. I think it is because of the threshold (0.415). When I see the histogram, I find that there is a number of the values after the threshold. I have got another question.
How can I obtain a value (in histogram) of a specific location in my image? Thank you.
Voss
Voss on 3 Feb 2022
To create a histogram of the region of 2D matrix Img12 containing rows start_row to end_row and columns start_column to end_column, you can say:
histogram(Img12(start_row:end_row,start_column:end_column))
i.e., just take the relevant part of Img12 using indexing when calling histogram().

Sign in to comment.

Answers (1)

KSSV
KSSV on 3 Feb 2022
If your image is a RGB image, the number of column will be product of second and third dimension if you just use size function.
DEmo
I = rand(10,10,3) ;
[m,n] = size(I)
m = 10
n = 30
% You have to use
[m,n,p] = size(I)
m = 10
n = 10
p = 3
Change your line number 28, so that you get Img12L value right.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!