Overlapping submatrices/sliding window and vectorization problem

6 ビュー (過去 30 日間)
Roey Ginzberg
Roey Ginzberg 2015 年 11 月 21 日
コメント済み: lavanya p 2016 年 4 月 13 日
Hello experts, I have a colored (RGB) image which I want to do the following:
  1. For each pixel I need to produce his 10X10 environment/neighbor pixels (lets say the pixel is in the middle) like sliding window. Thus, there will be overlaps of color images and that's what I want.
  2. For each 10X10 environment (or color image) I need to produce a vector according to a specific logic I have.
  3. Lastly, I need to save all vectors produced earlier for each pixel in some array/matrix (some structure).
FOR LOOPS are very slow in MATLAB. what you suggest me to do?
  3 件のコメント
Image Analyst
Image Analyst 2016 年 4 月 12 日
lavanya, I already gave an answer for this. Did you see it below? Did you run and adapt the demos? Use the one where I define a custom filter. In there you would put a call to graycomatrix().
lavanya p
lavanya p 2016 年 4 月 13 日
thank u so much

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

回答 (1 件)

Image Analyst
Image Analyst 2015 年 11 月 21 日
I think you haven't given the whole story,that's what I think. Who would want a gigantic list (perhaps 1 to 20 million) of 100 element vectors? What will they be then used for. To just give you the vectors, you can use blockproc(). I have demos. You can also use nlfilter() but that will probably be slower than a for loop.
AND can we dispel the myth that for loops are very slow? I can do a hundred million for loop iterations on my computer in 0.3 seconds. Would you call that slow? That's a lot of iterations in the blink of an eye. Sure, for some operations it can be slower than vectorized solutions but I'd hardly call them VERY SLOW - that's a myth. And most questions I see here do not have anywhere near that number of iterations, not even close.
  2 件のコメント
Roey Ginzberg
Roey Ginzberg 2015 年 11 月 21 日
Thanks for a quick answer!
I didn't understand how exactly I can retrieve all the sliding windows in one row of code (or a few...). I need a large list because I need to collect for every pixel- features that represents him and give this after to another algorithm- DBScan. Regards the slow time- I already tried it in FOR loops and it took seconds for every single row so that's why I posted this question. If something still not clear I will glad to clarify it. Again- thanks!
Image Analyst
Image Analyst 2015 年 11 月 21 日

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by