# 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?

3 views (last 30 days)
Haytham Ali on 16 Nov 2021
Answered: DGM on 16 Nov 2021
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 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.

Haytham Ali on 16 Nov 2021
Image Analyst on 16 Nov 2021
Try imtranslate().

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.
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;
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