MATLAB: How to create image matrix via

matrix

I have the following problem: I have a file.mat, containing a matrix 240X320. If I click on imagesc, I see an image referencing the matrix … Now, I want to select a portion of the image by clicking on "insert-> rectangle" and from there derive the submatrix. If I click with right mouse button I can show M-code, which gives me only the coordinates of the rectangle, but how can I obtain the submatrix?

Best Answer

  • No, that's not right. You need to convert your x,y from normalized values to values that correspond to pixel coordinates. Get the size of your image like this
    [rows columns numberOfColorChannels] = size(yourImageArray);
    Then multiply your x's by the columns, and the y's by the rows to get x and y in columns and rows instead of normalized units. Then get the submatrix like this
    submatrix = yourImageArray(row1:row2, column1:column2);