Parse inverse colors in matlab?

I draw on top of the image in Matlab. Sometimes I don’t see how to be built, because the color of the image below it is too close to the color of the image in the same place. I could always change the color of the plot (for example, from "rx" to "bx"), but this is cumbersome.

Is it possible to reverse the color of the bottom so that the overlay is always visible?

+6
colors matlab plot inverse
source share
4 answers

I find it impossible to automatically invert the plot color based on the background image. Perhaps you can rasterize the plot and somehow combine it with the image (xor?).

Here is another solution. If you can use closed markers, such as a circle, square, triangle, you can set different MarkerEdgeColor and MarkerFaceColor so that the marker is visible against different colors.

h = plot(1:5,'o'); set(h,'MarkerEdgeColor','b') set(h,'MarkerFaceColor','r') 
+3
source share

It is possible.

Assuming you know what your image is, you can do the following:

  • Read the color in the coordinates you draw

  • Invert color

  • Use the scatter

    % # load rgb color image - this may not be the best example, since everything is so dark. X = double (imread ('ngc6543a.jpg')) / 255; % #, since this is a rather dark image, invert it to half X (:, 1: gender (size (X, 2) / 2), :) = 1-X (:, 1: gender (size (X, 2) / 2), :);

    % # create some graph data plotX = rand (50,1) * size (X, 1); plotY = rand (50,1) * size (X, 2);

    % # read RGB components (it should be possible to do this more efficiently, but I don’t see% # this is plotColors = zeros right now (length (plot X), 3); with c = 1: 3 plotColors (:, c) = interp2 (X (:,::, c), plotY, plotX); end

    % # invert plotColors = 1-plotColors; % # If you want very different colors and avoid the problem that gray is the opposite of% # to gray, you can use% # plotColors = round (1-plotColors); % # This gives you a selection of wrgbcmyk, depending on what is further from the color of the image

    % # plot figure, imshow (X) Stay on the scatter line (plotY, plotX, [], plotColors)

Edit: This is now tested and should work.

Edit2: inverting half of the original image simplifies this

Edit3: modified gnovice suggestion form included

Edit4: fixed error indicated by AB

+2
source share

There is no automated way that I know that your plotted points change color depending on the color of the pixel behind them. Keep in mind that you do not need to use only eight predefined color specifications (ie “R” for red or “b” for blue). You can choose the RGB color specification for your plotted points, which is not usual for your main image. For example:

 h = plot(0,0,'Marker','x','Color',[1 0.4 0.6]); %# Plot a pink x 

You can programmatically find the least common color with some simple code that selects the least frequently used color values ​​in the image. Here is one example:

 rawData = imread('peppers.png'); %# Read a sample RGB image imData = reshape(rawData,[],3); %# Reshape the image data N = hist(double(imData),0:255); %# Create a histogram for the RGB values [minValue,minIndex] = min(N); %# Find the least used RGB values plotColor = (minIndex-1)./255; %# The color for the plotted points image(rawData); %# Plot the image hold on; hp = plot(500.*rand(1,20),350.*rand(1,20),... %# Plot some random points 'Marker','o','LineStyle','none',... 'MarkerFaceColor',plotColor,'MarkerEdgeColor',plotColor); 

The above code first converts the image data into an M-3 matrix, where M is the number of image pixels, and the three columns contain the values ​​of red, green, and blue, respectively. For each column, values ​​are bitted using HIST , then the value with the lowest bin (i.e. the lowest frequency) is found for each column. These three values ​​become the RGB triple for the plot color. When the image is superimposed on random dots of this color, it gives the following graph:

alt text

Please note that the code above selects a bright blue color for the graph points, which appears to be a color that does not appear on the image and thus gives good contrast.

+1
source share

It is very simple and looks good if you need to draw scattered points:

 %# load rgb color image X = double(imread('ngc6543a.jpg'))/255; %# since it quite a dark image, invert half of it X(:,1:floor(size(X,2)/2),:) = 1-X(:,1:floor(size(X,2)/2),:); %# create some plot data plotX = rand(50,1) * size(X,1); plotY = rand(50,1) * size(X,2); %# plot figure,imshow(X) hold on scatter(plotY,plotX,'xw'); scatter(plotY,plotX,'ok'); 

If you need something more complicated, leave me a comment.

0
source share

All Articles