MATLAB Can anyone with MATLAB installed test my code?

  • Thread starter Thread starter klawson88
  • Start date Start date
  • Tags Tags
    Code Matlab Test
Click For Summary
Access to MATLAB on campus is limited, and there is an urgent need to test code for an assignment due shortly. The code involves an image processing task where the user selects points on a source image to extract an area and then selects points on a target image to replace that area. The code provided includes a wrapper function and a frameit function to handle the affine transformation and image replacement.Key issues identified include the need to correct function names and capitalization errors in the code. Specifically, the function 'Disp' should be changed to 'disp', and 'cp2form' should be replaced with 'cp2tform' to ensure proper execution. Additionally, rounding of coordinates must be handled correctly to avoid errors. The user is seeking assistance to resolve these issues before the assignment deadline.
klawson88
Messages
3
Reaction score
0
Long story short, we have access to MATLAB on the computers on my campus. My plan was to code at home and return to campus to test my code, but a few things have come up that won't allow me to return to campus today. Deadline for an assignment is fast approaching (couple of hours), I just need to test it before handing it in (online).

All you have to do is specify the location of 2 images on your computer and a name for the result image in wrapper(targetFileName,sourceFileName,resultFileName). What the code is supposed to do is display the source image and ask you to click 4 points on it which surround an area you want to extract. It will then display the "target" image and ask you to click 4 points on that image that encompass the area that you want to replace. It will then perform an affine transformation and place the extracted area to the selected area of the target image and save it as what you put for resultFileName.

The .m files are attached and the source code is below. If anyone could help it would be greatly appreciated! If an error arises please reply and tell me what it is.

Thanks.

Code:
function w = wrapper(targetFileName, sourceFileName, resultFileName)

%Reads the target and source image files in
targetArray = imread(targetFileName);
sourceArray = imread(sourceFileName);


%Shows the source image and asks the user to click on 4 points,
%storing the coordinates in a matrix
Disp('Click on 4 points on the image that encompass the area you want to extract')
imshow(sourceArray);
[sourX,sourY]= ginput(4);


%Shows the target image and asks the user to click on 4 points,
%storing the coordinates in a matrix

Disp('Click on 4 points on the image that encompass the area you want to replace ')
imshow(targetArray);
[tarX,tarY] = ginput(4);





%Rounds the x and y values of the user-selected points to the
%nearest integer
[tarX,tarY] = round([tarX,tarY]);
[sourX,sourY] = round([sourX,sourY]);

%Calls the frameit function
frameit(targetArray, sourceArray, tarX, tarY, sourX, sourY, resultFileName);


Code:
function fi = frameit(targetArray, sourceArray, tarX, tarY, sourX, sourY, resultFileName)

%Performs an affine transformation on the user-selected area of
%the source image to make it fit to the user-selected area of the
%target image
transform = cp2form([sourX,sourY], [tarX,tarY], 'affine');


%Extracts the user-selected area from the source image
subSource = sourceArray([min(sourX):max(sourX)], [min(sourY):max(sourY)], : );


%Resizes the sub-image so that it has the same dimensions as the user
%selected area in the target image
%subSource = imresize(subSource, [max(tarX)-min(tarX), max(tarY)-min(tarY)]);

%Transforms the sub-image according to the transformation that was
%computed before 
sourceTransform = imtransform(subSource, transform);


%Replaces the user-selected area in the target image with the transformed
%user-selected area of the source image
targetArray((min(tarX):size(sourceTransform, 1), (min(tarY):size(sourceTransform, 2), : ) = sourceTransform;


%Shows the resulting image and saves it as a jpg file
result = targetArray;
imshow(result);
imwrite(result, resultFileName, 'jpg');
 

Attachments

Physics news on Phys.org
Function cp2tform in frameit.m is a part of Image Processing Toolbox. I don't have it, so the execution didn't complete. But here are some other errors I have corrected:

1. In wrapper.m, lines 10 and 18, Disp will be disp (no capital)

2. In wrapper.m, change lines 28 and 29 to this:
Matlab:
tarX = round(tarX);
tarY = round(tarY);
sourX = round(sourX);
sourY = round(sourY);

3. In frameit.m, cp2form will be cp2tform
 

Similar threads

Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
1
Views
8K
Replies
7
Views
3K