I want to make translation for this shape in binary image inside dictionary why when I try to move the center of the shape to point more than 1 this shape go out image frame?

1 view (last 30 days)
  7 Comments
Haytham Ali
Haytham Ali on 16 Nov 2021
@DGM thank you
Could you please tell me why if we take number more than 1 for center this shape go out the frame of the image
Is this because we use binary image or what?
DGM
DGM on 16 Nov 2021
centx and centy describe the location of the displaced image in normalized image coordinates. Assuming no scaling occurs, if you use centx,centy = 0.5, the image remains unchanged. If you use centy = 0.5 and centx = 1, the point which used to be in the center of the image is now translated to the center of the right edge. Using a center of 1.5 would push all possible image content out of frame.
I'm assuming the use of normalized image coordinates is by design, so I was assuming that was your choice.

Sign in to comment.

Answers (2)

Haytham Ali
Haytham Ali on 16 Nov 2021

DGM
DGM on 16 Nov 2021
Not knowing the details of what you're trying to really do, this essentially replicates the behavior, but using IPT tools. It's probably not faster or anything, but it does allow for the center to extend to negative values, which would be required for translations beyond the south or west edges.
a = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/801479/image.jpeg')>=128;
newcenter = [0.5 0.8]; % [x y]
scale = 0.5;
% resize without changing image geometry
s0 = [size(a,1) size(a,2)];
if scale > 1
a = imresize(a,scale,'nearest');
s = [size(a,1) size(a,2)];
ps = fliplr((s - s0)/2);
a = imcrop(a,[round(ps) fliplr(s0)-1]);
elseif scale < 1
a = imresize(a,scale,'nearest');
ps = (s0 - [size(a,1) size(a,2)])/2;
a = padarray(a,ceil(ps),0,'pre');
a = padarray(a,floor(ps),0,'post');
end
% translate
t = (newcenter - [0.5 0.5]).*[s0(2) -s0(1)];
a = imtranslate(a,t,'fillvalues',0);
imshow(a)
Again, the result can just be converted to sparse if needed

Community Treasure Hunt

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

Start Hunting!