shifting a part of image (not rectangular shape)

1 次查看(过去 30 天)
I have an rectangular shape image. In which there is an inclined line (not vertical or horizontal) separating that image into 2 parts. I want to shift one part of the image down by a fixed amount of pixels. how can do that

采纳的回答

Walter Roberson
Walter Roberson 2011-10-10
The question is not clear. Are you pulling one part of the image "away" from the dividing line, or are you pushing it "into" the dividing line?
If you are pulling it "away" from the dividing line, then what should go in to the new space between the dividing line and the new location, and what should happen with the part of the image that would protrude beneath the old bottom of the image?
If you are pushing it "into" the dividing line, should the pixels that would go above the line just be discarded? And what should go in to the empty space left by moving the image?
Is the inclined line a straight line defined by a start and end point, or do its boundaries need to be found by examining the image to detect some distinctive property of the boundary?
  3 个评论
Walter Roberson
Walter Roberson 2011-10-10
So the original pixels 495-500 can be thrown away if they would go beyond the edge?
Based upon your original description, I thought perhaps you wanted to shift a cut rectangular block -- rectangular until it hit the dividing line. But your answer has left me thinking that perhaps you meant something else?
Does the straight line only go through part of the overall image? When the rows are shifted, should the portion of the image between the left or right edge of the line and the edge of the image be left as-is?
An example might help.
http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
Walter Roberson
Walter Roberson 2011-10-10
That last should have been written in terms of the upper and lower part of the line edge, not the left and right part.

请先登录,再进行评论。

更多回答(3 个)

bes
bes 2011-10-10
im2=ones(500,500);
im2(1:100, :)=1;
im2(100:200,:)=2;
im2(200:300,:)=3;
im2(300:400,:)=4;
im2(400:500,:)=5;
imagesc(im2);
this is the input image
[x, y] = getline; % get the input line to separate the image into 2 parts
In output the righthand side part of the image should shifted down

bes
bes 2011-10-11
  4 个评论
bes
bes 2011-10-11
it can go to upward bottom left to top right

请先登录,再进行评论。


bes
bes 2012-10-3
I have solved this problem using this code
I have downloaded imTransD function from <http://www.csse.uwa.edu.au/~pk/research/matlabfns/Projective/imTransD.m>
[xCor, yCor] = getline; % get the line input from user
cor = [xCor(1), xCor(2), yCor(1), yCor(2)];
[rows, cols] = size(im);
[x y] = meshgrid(1:cols, 1:rows);
% Eqn of line joining end points (x1 y1) and (x2 y2) can be
% parameterised by
% x*(y1-y2) + y*(x2-x1) + y2*x1 - y1*x2 = 0
mask = (x*(yCor(1)-yCor(2))+ y*(xCor(2)-xCor(1))+ yCor(2)*xCor(1)- yCor(1)*xCor(2)) > 0;
m = (yCor(2)-yCor(1))/(xCor(2)-xCor(1));
dy = d;
dx = dy/m;
T = [1 0 dx; 0 1 dy; 0 0 1];
% Transformation matrix ( shift along x direction is d and in y direction is (d/m)
im2 = imTransD(im, T, size(im));
im = im.*(mask) + removenan(im2.*double(~mask), 0);
figure, imagesc(im);

类别

Help CenterFile Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by