PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 27, 2022

[FIXED] How to crop the sub-image using its centroid?

 July 27, 2022     centroid, crop, matlab     No comments   

Issue

To get a sub-image there is imcrop function. but I want to crop the sub-image using its centroid, (x,y) that was achieved already.

Image = 512x512
Centroid = (x,y) = (178.92, 207.20)

Also, the imcrop function doesn't get any input as Centroid.

B = imcrop(A, [col, row, width, height]; 

How to crop the sub-image using its centroid ?

Also, according to the specified size and position of the rectangle that is estimated using the center of (x, y)), the sub-image is cropped but its output wasn't correct.

Ex:

To calculate the input argument of `imcrop` function, we have:
Diam of Obj = 50 pixel. 
then its window = 50x50 pixel.
and so 57/2 = 28 to add and subtract of centroid.

Win_Obj = imcrop(RNod,[c(1)-28, c(2)-28, c(1)+28, c(2)+28]);

enter image description here


Solution

According to your post and also the docs, the function imcrop() uses a rectangle as second parameter in the form [x_min y_min width height], so you just need to change your call of imcrop to the following form:

% c is the known centroid position
Win_Obj = imcrop(RNod, [c(1)-28 c(2)-28 2*28 2*28]);

This should give you a sub-image with your object in the center.



Answered By - avermaet
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing