Can anyone with MATLAB installed test my code?

In summary, 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).
  • #1
klawson88
3
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

  • frameit.m
    1.1 KB · Views: 543
  • wrapper.m
    953 bytes · Views: 538
Physics news on Phys.org
  • #2
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
 

1. Can anyone with MATLAB installed test my code?

Yes, as long as the person has MATLAB installed on their computer, they can test your code. MATLAB is a widely used software for scientific computing and data analysis, so it is likely that many people have it installed.

2. Do I need to have a specific version of MATLAB for someone to test my code?

In most cases, no. MATLAB is backward compatible, meaning that newer versions can run code written in older versions. However, if your code uses specific functions or features that are only available in newer versions, then the person testing your code would need to have that version or higher.

3. Is it necessary for the person testing my code to have a strong background in MATLAB?

Not necessarily. While having a strong background in MATLAB can certainly be helpful in understanding and testing your code, anyone with basic knowledge of the software can run it and provide feedback.

4. Can the person testing my code make changes to it?

Yes, if you have given them permission to do so. MATLAB allows for collaboration and sharing of code, so you can choose to allow others to edit your code or simply view and run it.

5. Is there a limit to the size or complexity of code that can be tested by someone with MATLAB installed?

Technically, there is no limit to the size or complexity of code that can be tested with MATLAB. However, larger and more complex code may take longer to run and may require more computing power. It is always a good idea to optimize your code for efficiency before sharing it with others for testing.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
126
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Replies
7
Views
2K
Replies
10
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
0
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
30K
  • STEM Academic Advising
Replies
13
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • STEM Academic Advising
Replies
10
Views
5K
Back
Top