help with location of within image
1 次查看(过去 30 天)
显示 更早的评论
I would like help with the following,
You will then pass the i, j as inputs (along with any other necessary information) to a local function called indexLocation(i,j,..,…). (You must write this function!) The outputs of the function must be one of the following:
INSIDE (when the location i,j is not on the border)
NE (when the location i,j is a North East corner)
TOP (when the location i,j is on the top boundary of the image, and is not a corner)
RIGHT (when the location i,j is on the right boundary of the image and is not a corner)
BOTTOM (when the location i,j is on the bottom boundary of the image and is not a corner)
SE (when the location i,j is South East corner )
SW (when the location i,j is South West corner)
NW (when the location i,j is North West corner)
LEFT (when the location i,j is on the left boundary of the image, and is not a corner)
The attachment is what I have.
%Edit Rik: copied code from attachment to body
myimage_color = imread('sunflower1.jpg');
imshow(myimage_color);
myimage_grayscale = rgb2gray(myimage_color);
figure
imshow(myimage_grayscale);
[rows,cols] = size(myimage_grayscale);
N = rows;
M = cols;
for j=1:M
for i=1:N
myimage_grayscale(i,j)
end
end
4 个评论
Rik
2020-10-23
I would suggest taking a step back.
You need to create a function. That means one of your lines of code must start with the function keyword.
What does the function need to do? It needs to respond what kind of location the coordinates describe. Say I tell you I want to know if the pixel on row 200 and column 255 is on the edge of my image or not. What do you need to know before you can answer my question?
When writing a function, try to stick to this order:
- Write the purpose in a single line. This will be the first comment line in your function. Try to keep it below 79 characters.
- Describe the syntax. What inputs should your function be able to handle? Should it work for arrays, or only for scalar input? What data types are allowed?
- Describe the expected output. What should the user expect?
- Write the logical steps in comments.
- Only now can you implement your steps in actual Matlab code.
That order is not perfect nor is it law, but it is generally a good strategy.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!