Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7015579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:40:15+00:00 2026-05-27T22:40:15+00:00

Greetings Overflowers, I have a gray image matrix in MatLab and few specific pixel

  • 0

Greetings Overflowers,

I have a gray image matrix in MatLab and few specific pixel coordinates of that image.
I want to calculate the mean and standard deviation of values within a rectangular area in that matrix such that:

  1. it is positioned at an angle (e.g. 0, 45, 90, 135)
  2. it contains all the few pixels
  3. its area is minimum for each angle and its height >= its width

For now I would be happy if I can do so for the vertical, horizontal and both diagonals cases, though I would really appreciate if I can do it for any angle in hand.

Any ideas ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:40:16+00:00Added an answer on May 27, 2026 at 10:40 pm

    So, given the input angle theta, and bunch of coordinates points, you want the minimum enclosing rectangle at that angle (what does that mean? — the height axis is set at that angle? the width axis? And angle from vertical-clockwise (like headings) or horizontal-anticlockwise (like maths)?).
    Further more, we adjust the height so that it’s >= the width.

    In that case, I think the following might work:

    1. Convert the coordinates into a new coordinate system which is just the x-y axis rotated by angle theta (use a rotation matrix for this)
    2. Find the minimum enclosing rectangle in this coordinate system: this is now just finding the minimum enclosing rectangle in the horizontal-vertical dimensions (so we don’t need to worry about theta any more since we’ve already transformed the coordinates)
    3. Make sure the minimum enclosing rectangle has height >= width
    4. Convert the rectangle back to the original coordinate system (rotate it back by theta).
    5. Use these coordinates to calculate mean/stddev.

    Something like this could work (untested), tweak to your desire:

    % pts is 2xn
    % theta is in degrees, anticlockwise from horizontal.
    % returns 2xn matrix of indices into the min enclosing rectangle.
    function minClosingRect = calcMinEnclosingRect( pts, theta )
        % convert to radians and rotate by theta degrees ANTICLOCKWISE
        thRad  = theta*pi/180;
        rotMat = [ cos(thRad) -sin(thRad); sin(thRad) cos(thRad) ];
    
        ptsRot = rotMat * pts;
    
        % find minimum enclosing rectangle of ptsRot
        %  in the horizontal-vertical direction
        % this is just min/max coords.
        minX = min(ptsRot(1,:));
        maxX = min(ptsRot(1,:));
        minY = min(ptsRot(2,:));
        maxY = max(ptsRot(2,:));
    
        % make sure height >= width
        if (maxY-minY)<(maxX-minX)
            % NOTE: depending on how you want you can extend
            % - out the bottom
            % - the top
            % - centred (etc)
            % e.g. to make the rectangle taller out the bottom
            minY = maxY - (maxX-minX);
        end
    
        % construct indices into rectangle
        [X Y] = meshgrid( minX:maxX, minY:maxY )
    
    
        % convert indices back by rotating thRad degrees backwards.
        rotMatInv = [ cos(-thRad) -sin(-thRad); sin(-thRad) cos(-thRad) ];
        minClosingRect = rotMatInv * [X(:) Y(:)]';
    

    Then use it like this (the one caveat is X/Y vs i/j):

    minClosingRect = calcMinEnclosingRect( pts, theta );
    mean2( Img(minClosingRect) )
    std2(  Img(minClosingRect) )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, Overflowers! I am writing an application in PHP that will allow for editing
Greetings, I have a jqueryui autocomplete input that uses an ajax call to populate
Greetings! I have an issue here that i can't find. I am getting a
Greetings fellow amazonians We have certain f4v files from webtvinteractive.com that are not working
Greetings, I have a particular object which can be constructed from a file, as
greetings all i have a domain class named car and i have an object
Greetings, I'm working on a game project that uses a 3D variant of hexagonal
Greetings Stack Overflow community. I'm trying to make a function that can pop all
Greetings I may have imagined this but does anyone know if Last.fm previously used
Greetings, I have a view based application project where I have created an NSObject

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.