Matlab Programming Please help Thanks httpcarmauxcsgsuedumwe
Matlab Programming. Please help. Thanks
http://carmaux.cs.gsu.edu/~mweeks/csc4630/PICT0009.JPG
Use MATLAB to read the image, show it as a figure, then have the user select 2 points, crop the image, and show it as another figure.
First, read the image and display it. You will need to define \"filename\" as a string of the filename.
x = imread(filename);
imshow(x);
Now have the user (you) select 2 points.
title(\'Select 2 points\');
[a, b] = ginput(2);
Now, you will need to \"clean up\" variables \"a\" and \"b\". Inspect the values, and make sure they are integers within the boundaries of \"x\", changing them as needed. Then make a cropped image:
y = x(r1:r2, c1:c2);
figure();
imshow(y);
title(\'cropped version\');
Once you have this working, crop it so that the lower-right corner is showing, about 1/4 of the original size.
Solution
x = imread(\"dc.png\"); %load image
imshow(x); %show the image
pos = get(gcf, \'Position\'); %Define image position
width = pos(3); % get the width of the image
height = pos(4); % get the height of the image
title(\'Select 2 points:\');
r1=input(\"\ Enter X cordinate of point 1: \");
c1=input(\"\ Enter Y cordinate of point 1: \");
r2=input(\"\ Enter X cordinate of point 2: \");
c2=input(\"\ Enter Y cordinate of point 2: \");
if r1 < 1 || r1 > width
fprintf(\"Invalid X cordinate of point 1\ Max range is 1 to %d\", width);
return;
end
if c1 < 1 || c1 > height
fprintf(\"Invalid Y cordinate of point 1\ Max range is 1 to %d\", height);
return;
end
if r2 < 1 || r2 > width
fprintf(\"Invalid X cordinate of point 2\ Max range is 1 to %d\", width);
return;
end
if c2 < 1 || c2 > height
fprintf(\"Invalid Y cordinate of point 2\ Max range is 1 to %d\", height);
return;
end;
y = x(r1:r2, c1:c2);
figure();
imshow(y);
title(\'cropped version\');
