I am trying to read an input image using octave and plot its RGB values as a 3 dimension plot.
I am reading image using
im = imread('image')
How can I plot this?
Also, is it possible to plot a histogram of all the 3 layers?
Thanks
As already stated, the Octave API doc gives you an MxNx3 matrix data set of your image.
The R/G/B channels are the last dimensions of your im matrix. hist needs 1d input, so we'll need to reshape it:
hist(reshape(im(:,:,1),1,[])) # red
hist(reshape(im(:,:,2),1,[])) # green
hist(reshape(im(:,:,3),1,[])) # blue
About the 3D plot: do you mean a 3D scatter plot? Then Octave's scatter3 might help you.
Related
Unsure if a polar plot is exactly what I should be using to accomplish this. But, essentially, I have multiple time-series (just amplitude vs. time), each corresponding to a different angle in degrees. For example, I have ampl. vs time at 5 degrees, 10 degrees, 15, etc. For angles 0 to 360 at increments of 5, I would like to plot each time series on a circular, or polar plot.
I am attempting to do this with matplotlib and the projection='polar' flag on. There are 8000 amplitude values for each time-series. They are in a numpy array called data. To test plotting the time-series associated with 5-degrees, I made a numpy array of 8000 5's with 5*np.ones(8000) so that they are the same length.
thetas=np.arange(0,365,5) #make 0 to 360 degrees at increments of 5
ax=plt.subplot(111,projection='polar') #turn on polar projection
ax.plot(5*np.ones(8000),data)
plt.show()
I get:
You can see these data are not plotting along the 5-degree line, nor does it look like any amplitudes are showing (there should be squiggles up and down varying with time). Thank you in advance!
EDIT: Example of what I want (each color line is a different time-series)
I have a dataset that has x,y,z columns. I have created surface plot using gnuplot and contour on top and bottom as see below. Here is the dataset: https://www.dropbox.com/s/8evj5da7yco1xmo/datx.dat?dl=0
Below is the plot from the data in the link.
I'm trying to create a contour plot like the one below with contours on the side, how do I accomplish this in gnuplot?
Here is the solution http://gnuplot-tricks.blogspot.com/2010/ but I'm unable to replicate it for my dataset.
I am trying to visualize results from varying three different parameters using gnuplot. I can produce a 4D plot by using an xyz scatter plot with color as the fourth dimension. Now what I want to do is to take the limited data I have and produce higher quality images. As seen below, if I angle the 4D plot in just the right way I can get what looks like a series of 3D plots along one dimension. Is there a way I can individually interpolate these 3D slices and obtain smoothed planar surfaces for the cross-sections instead of the scatter plot form I currently have?
4D Scatter Plot Angled to Look Like 3D Cross-Sections:
New in version 5.4 (please try and report on the release candidate!)
http://gnuplot.sourceforge.net/demo_5.4/voxel.html
I am trying to plot the r,g,b channels in an image as a 3-D scatter plot.
This works well when i have a black and white image as i get a scatter plot with just two distinct clusters at two ends of the scatter plot.
However for color images the scatter plot does not make much sense visually because there are r,g,b values corresponding to many points in the color space in the image.
So i end up with something like the image shown below -
What i would like to achieve is somehow represent density information. For example if the number of points corresponding to (255,255,255) are 1000 and the number of points corresponding to (0,0,0) are only 500 then i want (255,255,255) to be dark red and (0,0,0) to be yellow/orangish
How do i achieve this in matplotlib? I am okay with some sort of bubble effect as well where the (255,255,255) is represented as a bigger bubble compared to (0,0,0) although i feel density information encoded as color information would be more visually appealing
Here's an attempt using Gaussian KDE. It's still far from perfect and the result largely depends on the estimation parameters (bw_method). There is perhaps a simpler way, maybe something using np.unique to get the frequency of each unique colour.
The idea is to estimate color density distribution as a multivariate gaussian mixture and use that as a colormap for the scatter plot.
It's a bit slow for anything serious but I think it gives nice results with small enough images. Maybe some FFT+convolution based estimation method could be faster.
Let's see some code. Nothing fancy: it flattens and reshapes image data the way gaussian_kde likes it and return RGB and density components. You can play with bw_method and see how the results change, the bigger, the smoother density you'll get.
from scipy.stats import gaussian_kde
def img_to_rgbk(img, bw=0.1):
rgb = img.reshape(-1, 3).T
k = gaussian_kde(rgb, bw_method=bw)(rgb)
r, g, b = rgb
return r, g, b, k
Here's the results with a toy image
img = chelsea()[100:200, 100:200]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
r, g, b, k = img_to_rgbk(img, bw=0.5)
ax.scatter(r, g, b, c=k, alpha=0.2)
Notice c=k is used to set map marker color to the density information, alpha is needed to see a bit through the cloud.
Chelsea
Random colors
Gradient
Note here you can see how the wrong choice of bandwidth can be misleading. A small enough bw_method should reveal essentially a single color per column, repeated along rows. So every dot should have the same color (and it will with the right bandwidth).
Gradient + noise
Here with a better bandwidth and some noise to spread the colors. Notice the bigger density around the white-ish area where the discontinuity in the no-noise plot becomes a density maximum.
So, here I am trying to plot heatmaps in gnuplot. I have a matrix-formatted text file (with row and column headers), and the command I am using to plot it is
plot "file.txt" matrix rowheaders columnheaders using 1:2:3 w image notitle
The output is this graph:
Obviously, the X and Y labels are useless like this. I believe the problem here is that gnuplot is extracting all labels from the file and plotting them. How would I go about reducing the amount of clutter in here, e.g. plotting every 10th label or so?
Thanks in advance.
Or just make the picture resolution bigger... for instance like 1920,1080 or bigger... like this:
set term pngcairo size 1920,1080
or make the tics numbers like 1000000 smaller and make a label to show that the numbers written on the tics are 1000000 bigger... or both:)
Sorry for my english...