shifting a part of image (not rectangular shape)

조회 수: 1 (최근 30일)
bes
bes 2011년 10월 10일
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 2011년 10월 11일
ya it always goes the entire height

댓글을 달려면 로그인하십시오.


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