Flip the image with non built-in function in Matlab

The input is gray scale image and the output is also the same.

Flipping the image up side down with non built-in function in Matlab
ty-exexch-koAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yuk99Commented:
If your image is RGB (m x n x 3 matrix) you can do:

Im2 = Im1(end:-1:1,:,:);

If the image is indexed (m x n matrix associated with a colormap) it's even simpler:

Im2 = Im1(end:-1:1,:);

for indexed image you can also use FLIPUD:

Im2 = flipud(Im1);

To show the resulted image:

imshow(Im2)
TommySzalapskiCommented:
If you want it as a non built in function. (Why? They are a lot faster.) Just use a loop.
I assume since it's a grayscale image, there is only one channel.

i = 0;
j = height - 1;

while i < j
  for x=0:width-1,
    swap(img(x, i), img(x, j));
  end
end

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ty-exexch-koAuthor Commented:
Hello TommySzalapsk

I know there available built-in function but I need to understand that function/algorthim by using not built-in function by re-programming by separate functions.

Can you TommySzalapsk write a complete code for that.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

yuk99Commented:
ty-exexch-ko,
Does my answer make sense for you?

ty-exexch-koAuthor Commented:
Yuk99 your answer not correct I don't want built-in function to do the flip of image.
yuk99Commented:
FLIPUD I listed just as an alternative. Although it's build-in function, it's for any 2D matrix, not for images.
But my first examples do not use any functions, but basic MATLAB operation with indices. Using loops is not recommended in MATLAB if it's possible to avoid them.
ty-exexch-koAuthor Commented:
Yuk99 please go outside from this question because you do waste of time

Regards
ty-exexch-koAuthor Commented:
Mr TommySzalapski

What is height ? Are this a function or what ?
TommySzalapskiCommented:
height is just the height of the image. If you open or create the image, you should be able to get the height and width from there.
The way it works is it just swaps the top row of pixels with the bottom ones and then the next row down with the next row up etc.

yuk99's answer does the same thing with a built-in operator.
yuk99Commented:
ty-exexch-ko,

If you don't like the answer, it doesn't mean the answer is wrong. It means either you don't understand the answer or didn't formulate the question correctly.

If you like the answer you accepted, good for you. I doubt it will work. It least not in MATLAB. There are at least 3 major problems.

Don't be rough with experts even if you are paying for the service. We are just volunteers here trying to help you in our free time.

As for me I should pay more attention who asks the question before answering it. I'll try to do it in the future.

Good luck.
TommySzalapskiCommented:
>> It means either you don't understand the answer or didn't formulate the question correctly.

yuk, he put "non built-in function" in bold. How was that not formulated correctly? This seems like more of an algorithms question than a MATLAB question (but it was posted in the Algorithms and Math&Science zones). It's perfectly legitimate. I believe you just read the question too quickly. (I do that occasionally too).

ty-exexch-ko, your comment did seem rude. I understand you may not have intended it to be (English seems to not be your first language). We are volunteers and try to give the answers that are asked for. Sometimes we just make mistakes.
yuk99Commented:
Tommy, thanks for the comment.
Again matrix indexing is not build-in function, but the MATLAB language feature. Since the question was about MATLAB I believe it's appropriate to use the language. The asker didn't specifically ask about algorithm (however I have to admit that I didn't notice the Algorithm zone) or how to do it in other language like C. The question was specifically about MATLAB. I very much recognize you as the expert, but I'm sorry, the code you gave is not MATLAB.
Let us finish this conversation here. The question is closed and I hope it will give something useful to future visitors without any further flame.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.