convert image size from 256*256 to 256*486

2 views (last 30 days)
How can i convert the following image size from 256 * 256 to 256 * 486?
In other words; The range of x changes in the following code is from 1 to 255 and the range of y changes is from 1 to 486.
A=ones(size(A));
for (x= 236: 255)
for (y=60: 80)
A(x,y)=0;
end
end
  2 Comments
DGM
DGM on 24 Apr 2021
I don't know what you're trying to do. If you don't want A to be a certain size, don't make it that size. Your x and y are flipped. The image doesn't match the code.
This whole thing can be reduced to this:
A=ones(256,486);
A(236:255,60:80) = 0;

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 24 Apr 2021
A(x,y)=0;
No, in MATLAB, the first dimension is y, and the second dimension is x.
The first dimension is row, which is vertical distance, which is y. The second dimension is column, which is horizontal dimension, which is x.
You have not told us the rule for having selected 60:80 . Your 236:255 is 20 pixels wide at the extreme edge of the image, and we can easily use end-20+1:end indexing for that. But your 60:80 is 21 pixels, and it is not clear why you choose 60. Something almost but not quite 1/4 of the way through the image??
When you say that the range of y will change, is the implication that you want to change to a different aspect ratio such as 20 x 38 pixels? Or is the implication that you want to put in more of the black near-squares? Or you want the same number but further apart?

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!