フィルターのクリア

sub2ind is not giving me diesired results

1 回表示 (過去 30 日間)
Lora
Lora 2015 年 1 月 19 日
コメント済み: Lora 2015 年 1 月 19 日
Hi how can you find linear indices of a certain rectangular region in an image. I have its x,y width and height i also have image width and height. Sub2ind is not working or perhaps i dont know how to achieve it using sub2ind. I only want linear indices of a 23x51 area. My X cordinat is 237 and Y is 228 and image size is 375,500. So if provide something like this
linearInd = sub2ind([23 51], 237, 228);
obviously it prompts error that out of range subscript
Thanks

採用された回答

Guillaume
Guillaume 2015 年 1 月 19 日
編集済み: Guillaume 2015 年 1 月 19 日
The first argument to sub2ind is the size of your whole image, not the region you want to extract. The second and third arguments would be the coordinates of the image you want to convert to indices. One way to do what you want:
img = randi([0 255], 512, 512); %random 256x256 image for demo
x = 237, y = 228, width = 51, height = 23;
[xx, yy] = meshgrid(x:x+width-1, y:y+height-1);
indices = sub2ind(size(img), yy, xx);
I have to ask, though, why do you want to convert to linear indices?
  1 件のコメント
Lora
Lora 2015 年 1 月 19 日
It workss thanks. The reason why i am trying to extract is that have ground truth objects in linear indices nd it would be easier to compute overlap.

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 1 月 19 日
編集済み: Azzi Abdelmalek 2015 年 1 月 19 日
You have a problem with the size of your matrix, if your matrix is 23x51 how can you get the coordinates [237 228]?
  1 件のコメント
Lora
Lora 2015 年 1 月 19 日
編集済み: Lora 2015 年 1 月 19 日
yes I know but my question is how can i get linear indices of a just a rectangular region of an image of size(375,500) now the size of my rectangular region is 23x51? but my rectangular region start from (237,228)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by