dustinboettcher
dustinboettcher

Reputation: 515

Matlab: replace matrix values

I have an image which I read:

p = imread('file');

In that image are 30px wrong. After (row50 column100) are those 30 misplaced. I want to replace those with 30px located after (row50 column200). How do I do that?

This is all I got so far:

new = p(p(200, 50):p(200, 50)+30);
pnew = [ p(1:p(100, 50)) new p((p(100, 50)+31):end)];
figure, imshow(pnew);

But it doesn't work @all :(

Upvotes: 0

Views: 96

Answers (1)

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38032

If I understand you correctly, you want to replace a block of 30×30 pixels at a given location in your image, with another 30×30 block somewhere else in your image.

If that is the case, you can use this:

pnew = p;
pnew(100:100+29, 50:50+29) = p(200:200+29, 50:50+29);

Upvotes: 3

Related Questions