Link to home
Start Free TrialLog in
Avatar of ty-exexch-ko
ty-exexch-koFlag for Albania

asked on

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
Avatar of yuk99
Flag of United States of America image

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:

Avatar of TommySzalapski
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ty-exexch-ko


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.
Does my answer make sense for you?

Yuk99 your answer not correct I don't want built-in function to do the flip of image.
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.
Yuk99 please go outside from this question because you do waste of time

Mr TommySzalapski

What is height ? Are this a function or what ?
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.

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.
>> 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.
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.