问题
Arrange the 2 given images into one image with image1 (pedestrian) on the left and image2 (no-parking) on the right in one single image. Display the combined single image.


Code 1 :-
z = imread('NO_PARKING.jpg');
x = imread('PEDESTRIAN.jpg');
r = imresize(z,[500,500]);
c = cat(2,x,r);
imshow(c)
Code 2:-
[X1,map1]=imread('PEDESTRIAN.jpg');
[X2,map2]=imread('NO_PARKING.jpg');
subplot(1,2,1), imshow(X1,map1)
subplot(1,2,2), imshow(X2,map2)
Which of the above codes is correct?
回答1:
The two codes don't do the same thing, so it's not a matter of efficiency. One combines the two images into one, then displays that one image, one just displays the two images in one figure.
If you really want to understand the difference in practice, you may consider:
Using two images which are different sizes
Using two images which are the same size but do not have white backgrounds
A further operation, such as rendering the combined image greyscale or applying a smoothing filter
来源:https://stackoverflow.com/questions/53570987/which-one-of-the-following-is-an-efficient-code-for-this-matlab