Circular region in an image
Show older comments
I am trying to replace a circular region in one image with the corresponding region in another image. Here is my code so far:
% Sample images:
I=imread('office_1.jpg');
I2=imread('office_5.jpg');
[imageSizeY, imageSizeX,z1] = size(I);
centerX = ceil(imageSizeX/2);
centerY = ceil(imageSizeY/2);
radius = 200;
for i=1:max(imageSizeY,imageSizeX)
if (((centerY+i) - centerY).^2 ...
+ ((centerX+i) - centerX).^2 <= radius.^2)
I(centerY:centerY+i, centerX:centerX+i, :) ...
= I2(centerY:centerY+i, centerX:centerX+i, :);
end
end
imshow(I)
Unfortunately, my code does not work correctly, and instead of a circle the result is a square (corresponding to only one quadrant of the desired circle):

What are the mistakes here? Any explanation is greatly appreciated.
Accepted Answer
More Answers (2)
Image Analyst
on 15 Jan 2018
1 vote
See my attached copy and paste demos.
Prince Masedi
on 18 Jul 2018
0 votes
II. Determine the following statistical parameter using Matlab program (Note you must copy and paste your code on the answer booklet. (1. Error variance, 2. Assume X=Rainfall Y=Runoff fill in the table with respective determined square of (X-Xm) where Xm is the mean of X and determine estimated Y termed as Yest.
1 Comment
Image Analyst
on 18 Jul 2018
How does this answer the original question about pasting circular regions into an image?
Categories
Find more on Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!