This is a bit more of a general question, however, no matter how many times I read the details of MATLAB's im2col function, I can not fully understand computational efficiency because I need it because MATLAB is horrible with the nested for loop. Here's what I'm trying to do, but using nested for loops:
[TRIMMED] = TM_FILTER (IMAGE, FILTER_SIZE, PERCENT) takes a 2-D array Returns the array, which is filtered with a squire which means the filtration FILTER_SIZE is equal to the length / width and percentile PERCENT. %} Function [trim] = TM_filters (image, filter_size, percentage) if rim (filter_ size, 2) == 0% make sure that the filter has a center pixel error ('the filter size should be odd numbered' ); % Error and return if the number is the end of the weird return if percent & gt; 100 || Percentage & lt; 0 error ('should be percent? [0, 100]'); End of return [rows, columns] = size (image); % Need for figure shapes n = (filter_size-1) / 2; The distance of% N pixels extends from center pixels to borders (= palette (image, [n, n], 128)); % Padding Limits In this center pixels, there is always a neighborhood for i = 1 + n:% rows of rows from the first non-padded insertion with entries from the previous non-plates for 1 = n: Column% colums first non-padded entry Subimage = Padded in the entry of the previous non-platon (in: I, N, JN: j + n); Average Average Filter =% (Trimimen (Subimage, Percent), Percentage); % Trimmed the vector of waste device means trimmed (i-n, j-n) = average; Average pixel in% simplified over and trim = UIT8 (trim); Converts the image from% 0-255
Here is the code that you want : Note that the entire nested loop was replaced with a statement. [TRIMMED] = TM_FILTER (IMAGE, FILTER_SIZE, PERCENT) takes a 2-D array and returns to the array, which means a squire trim is mean with the mean of the filter / Length is equal to FILTER_SIZE and is equal to PERCENT percent. %} Function [trim] = TM_filter (image, filter_size, percentage) if rim (filter_us, 2) == 0% Make sure the filter has a center pixel error ('the size of the filter should be odd numbered') ; % Error and return if the number is the end of the weird return if percent & gt; 100 || Percentage & lt; 0 error ('should be percent? [0, 100]'); Return and trim = (UIT 8) trimman (IM2 call (image, filter_ shape), percent);
Explanation:
im2col functions changes each region of filter_size in a code. Your trimmean function can then operate on each area (column) in a single operation - more efficient than extracting each shape in return, note that only for this trimmean < / Code> requires only one application - you first do it on the columns, then do it on rows, which is actually caused by a more serious trim, which I think is that you want 50% for the first time, then 50% Then - like leaving 75% It is Not exactly right, but you have to say to me). In addition you will find that changing the order of operation (line, then column vs. column, then row) will change the result, because the filter is non-linear. For example
IM = new shapes (1: 9, [3 3]); Results in Disp (im2col (im, [2 2])
1 2 4 5 2 3 5 6 4 5 7 8 5 6 8 9 Since you have taken each of the 4 possible blocks of this matrix:
1 4 7 2 5 8 3 6 9 and changed them into columns
Note - With this technique (applicable to the missing image) you lose some pixels on the edge; your method adds some padding so that Each pixel (even on the edge) is a full neighborhood, and such as Phil The tender gives an image that is the same size as the original (but it is not clear that the effect of padding / filtering will be near the margin and especially near the corner: you have fixed around 75% percent pixels on 128 pixels and this corner Is likely to dominate behavior in).
No comments:
Post a Comment