How to Read Multiple Image in Matlab

Show an image in a MATLAB 3D surface plot with a separate colormap

T he surface / surf plot in MATLAB can visualize information in 3D. When I took a course in grad school on statistical image processing, I saw a very interesting plot where information is shown every bit a surf plot and underneath, on the ground or 10-y plane, an image is shown. The pixels of the paradigm corresponded to the points in the 3D surface and gave some extra information about the each bespeak, sort of similar an image-based version of surfc or a 3D version of plotting over an image background. I always wanted to know how to make that plot but rather than asking the prof who made it (every bit one is supposed to after paying tuition), I decided to figure information technology out on my own (thus proving why I was never practiced at accounting). It took some experimentation but I finally figured out how this type of plot is accomplished. In this tutorial, I volition show how to exercise this and how to brand information technology so that the surface plot and the prototype can use dissimilar colormaps, getting around the restriction that MATLAB only has 1 colormap per figure. In outcome, this will simulate multiple colormaps. The event volition look something like this:

Image shown as a texture mapped plane in a MATLAB 3D surface plot

Annotation how the image is mapped to a airplane and is shown with a jet colormap while the 3d surf is shown with a gray colormap.

Basic way to show an paradigm on the aforementioned axes equally a 3D surface

I will commencement get through the basic style to do this without multiple colormap back up. Take a look at this lawmaking:

            % the data that you want to plot equally a 3D surface.            [x,y,z]            =            peaks;            % get the corners of the domain in which the data occurs.            min_x =            min            (            min            (x)            ); min_y =            min            (            min            (y)            ); max_x =            max            (            max            (x)            ); max_y =            max            (            max            (y)            );            % the image information you want to bear witness as a plane.            planeimg =            abs            (z);            % set hold on so we can show multiple plots / surfs in the figure.            figure;            agree            on;            % do a normal surface plot.            surf            (x,y,z);            % gear up a colormap (just this has no outcome because the next colormap            % control overwrites it)            colormap            (            grayness            );            % desired z position of the prototype plane.            imgzposition = -10;            % plot the image plane using surf.            surf            (            [min_x max_x],[min_y max_y],repmat            (imgzposition,            [            2            2            ]            ),...            planeimg,'facecolor','texture'            )            % set a colormap for the figure.            colormap            (            jet            );            % set the view bending.            view            (            45,thirty            );            % labels            xlabel            (            'ten'            );            ylabel            (            'y'            );            zlabel            (            'z'            );

The higher up code volition produce this plot:

Image shown as a texture mapped plane in a MATLAB 3D surface plot

I first created the 3D data to be plotted by making employ of the peaks part. Next, I establish the domain of the data (extent in the x-y plane). This is used to define the plane that the image volition be mapped to in the concluding plot. The epitome to exist shown is stored in planeimg (in this case I only used abs(z) simply the image can any arbitrarily sized array of data - it will be stretched or squeezed to fit the plane divers by the extent of the domain of the data). I then plotted the 3D data by calling surf. Finally, the paradigm is mapped to a plane parallel to the x-y airplane by the following lines:

            % desired z position of the paradigm airplane.            imgzposition = -10;            % plot the image plane using surf.            surf            (            [min_x max_x],[min_y max_y],repmat            (imgzposition,            [            2            two            ]            ),...            planeimg,'facecolor','texture'            )

imgzposition sets where on the z axis the image plane is to be placed; I set -10 so it would not intersect with the existing 3D surface. The surf command here has defined a planar surface with the post-obit vertices:

(min_x, min_y, imgzposition)

(max_x, min_y, imgzposition)

(max_x, max_y, imgzposition)

(min_x, max_y, imgzposition)

To empathise how this works, refer to MATLAB's surf documentation, which states:

surf(X,Y,Z) creates a shaded surface using Z for the color data likewise equally surface height. X and Y are vectors or matrices defining the 10 and y components of a surface. If Ten and Y are vectors, length(10) = n and length(Y) = k, where [g,north] = size(Z). In this case, the vertices of the surface faces are (X(j), Y(i), Z(i,j)) triples.

In whatever case, the planeimg is used as a texture map for the single confront of the planar surface.

You volition have noticed that I actually have two colormap commands in the code, but both the 3D surface and the image accept the same colormap. This is considering in that location is merely one colormap for the effigy. The adjacent section volition discuss how to get around this and apply a unlike colormap for the 3D surface and the paradigm plane.

Show the image with a different colormap by faking multiple colormaps

To give the image a unlike colormap than the 3D surface, all I demand to do is convert the epitome (which is just a 2D array of values) into a true colour image according to the desired colormap. This is how:

            % scale the between [0, 255] in society to use a custom color map for it.            minplaneimg =            min            (            min            (planeimg)            );            % observe minimum outset.            scaledimg =            (            floor            (            (            (planeimg - minplaneimg)            ./            ...            (            max            (            max            (planeimg)            )            - minplaneimg)            )            *            255            )            );            % perform scaling            % convert the paradigm to a true color image with the jet colormap.            colorimg = ind2rgb(scaledimg,jet            (            256            )            );

Due to the style colormap and ind2rgb work, the prototype must first be scaled to between [0, 255] before being converted to true colour. I also take to specify a 256 element colormap (since [0, 255] has 256 possible values).

Now all we accept to practice is instead of showing planeimg, we show colorimg instead:

            % plot the prototype plane using surf.            surf            (            [min_x max_x],[min_y max_y],repmat            (imgzposition,            [            2            2            ]            ),...            colorimg,'facecolor','texture'            )          

This will produce a figure very similar to the one at the offset of this tutorial. If you want to become rid of the wireframe mesh (as I did), and then simply specify 'edgecolor' to exist 'none' in your surf commands:

            surf            (x,y,z,'edgecolor','none'            );

Complete code snippet

Here it is birthday:

            % the data that you want to plot equally a 3D surface.            [x,y,z]            =            peaks;            % go the corners of the domain in which the data occurs.            min_x =            min            (            min            (x)            ); min_y =            min            (            min            (y)            ); max_x =            max            (            max            (x)            ); max_y =            max            (            max            (y)            );            % the image data you want to show equally a plane.            planeimg =            abs            (z);            % scale image between [0, 255] in order to utilize a custom colour map for it.            minplaneimg =            min            (            min            (planeimg)            );            % detect the minimum            scaledimg =            (            floor            (            (            (planeimg - minplaneimg)            ./            ...            (            max            (            max            (planeimg)            )            - minplaneimg)            )            *            255            )            );            % perform scaling            % convert the image to a true color image with the jet colormap.            colorimg = ind2rgb(scaledimg,jet            (            256            )            );            % set agree on so we tin testify multiple plots / surfs in the effigy.            effigy;            hold            on;            % do a normal surface plot.            surf            (10,y,z,'edgecolor','none'            );            % set a colormap for the surface            colormap            (            gray            );            % desired z position of the image plane.            imgzposition = -10;            % plot the image plane using surf.            surf            (            [min_x max_x],[min_y max_y],repmat            (imgzposition,            [            2            ii            ]            ),...            colorimg,'facecolor','texture'            )            % set up the view.            view            (            45,thirty            );            % label the axes            xlabel            (            'x'            );            ylabel            (            'y'            );            zlabel            (            'z'            );

This volition produce the effigy shown at the beginning of the tutorial:

Image shown as a texture mapped plane in a MATLAB 3D surface plot

remleydertuary.blogspot.com

Source: http://www.peteryu.ca/tutorials/matlab/image_in_3d_surface_plot_with_multiple_colormaps

0 Response to "How to Read Multiple Image in Matlab"

Enregistrer un commentaire

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel