Understanding Image Resizing Code
    3 次查看(过去 30 天)
  
       显示 更早的评论
    
Matlab newbie here, so please be gentle.
I am trying to port some Matlab code to C++ and am having trouble following the code that should resize an image.
What the underlying code is supposed to be trying to do is normalize line segments (which maybe/are curvy). Thus, when done each segment should have the same X length but potentially varying Y heights.
The code that is supposed to do this follows:
function func_normalize_shape(im_name )
  I = imread( im_name );
    if size(I, 3) > 1
        for i=1:size(I,3)
            a=(I(:,:,i));
            if max(max(a))~=min(min(a))
                I=a;
                break               
            end
        end
    end
      I = no_border_img(I, 1);
      I = imresize( I, sqrt(200000/(size(I,1)*size(I,2))) );
      I = no_border_img(I, 5);
As I understand it, the contents of the file are read into "I". The third dimension indicates how many images (in this case, I guess line segments), there are. Then, the code cycles through the images.
Here is where I start getting lost. The contents of one image are loaded into "a" (but, why an extra set of parathesis?). The clause "max(max(a))" should find the maximum number for the three dimensions of "a", then take the maximum of each that to arrive at a single number. Do the same thing for the minimum. I am losy here as to what the line "I=a" would do.
Any help on understanding this code, appreciated.
0 个评论
采纳的回答
  Jan
      
      
 2017-2-28
        The extra parenthesis in a=(I(:,:,i)); is not needed, but you are allowed to add as many of them as you like. This is useful if it improves the readability of the code or to point out the intention. But here this looks confusing only. Replace it:
a = I(:,:,i);
Now a has 2 dimensions, not three, because the trailing singelton dimension vanishes in Matlab.
The command max(max(a))~=min(min(a)) determines, if a has at least two different values. More efficient:
if ~all(a(:) == a(1))
If this is true, the variable "I" is replaced by the current sub-array of I:
I = a;
and the for loop is stopped. In other words:
 For the image I, find the first submatrix along the 3rd dimension, which has at least
 to different values.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

