Azzera filtri
Azzera filtri

shifting a part of image (not rectangular shape)

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 10 Ott 2011
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 Commenti
Walter Roberson
Walter Roberson il 10 Ott 2011
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 il 10 Ott 2011
That last should have been written in terms of the upper and lower part of the line edge, not the left and right part.

Accedi per commentare.

Più risposte (3)

bes
bes il 10 Ott 2011
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 il 11 Ott 2011
  4 Commenti
bes
bes il 11 Ott 2011
it can go to upward bottom left to top right
bes
bes il 11 Ott 2011
ya it always goes the entire height

Accedi per commentare.


bes
bes il 3 Ott 2012
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);

Community Treasure Hunt

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

Start Hunting!

Translated by