필터 지우기
필터 지우기

Creating a rectangle image by using an user defined function

조회 수: 3 (최근 30일)
Mert Aygün
Mert Aygün 2018년 5월 18일
편집: Mert Aygün 2018년 5월 18일
I am trying to create a rectangle image as you see but I have a problem with the equation part of the rectangle. Can anyone help to fix this up? Thank you in advance.
function outimg = RectIm(x, y)
SizeX = 256;
SizeY = 256;
[C, R] = meshgrid(1:SizeX, 1:SizeY);
centerX = 128;
centerY = 128;
rectangle = (R - centerY/2)*(C - centerX/2) <= x*y ;
outimg=image(rectangle);
colormap([0 0 0.4; 1 1 1]);
end

채택된 답변

Walter Roberson
Walter Roberson 2018년 5월 18일
rectangle = (R - centerY/2).*(C - centerX/2) <= x*y ;
This is not going to define a rectangle, though: it is going to define a hyperbola.
Perhaps you want
rectangle = abs(R - centerY/2) <= y/2 & abs(C - centerX/2) <= x/2 ;
  댓글 수: 1
Mert Aygün
Mert Aygün 2018년 5월 18일
편집: Mert Aygün 2018년 5월 18일
This is almost what I want. Except, I would like the put the rectangle in the middle of the image. Therefore, the code should be
rectangle = abs(R - centerY) <= y/2 & abs(C - centerX) <= x/2 ;
Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by