1

I have a plot that needs to be contrast enhanced before another plot is superimposed over it.

figure
plot(something);
** contrast enhancement **
hold on
plot(something_else);
hold off

Is there a way to do this in the ** contrast enhancement ** line above? I have looked into imadjust function but it takes direct image input (tif/jpeg etc.).

Thank you.

Edit: Example code -

figure
plot(ebsd,ebsd.prop.bc);
mtexColorMap black2white
** contrast enhancement **
hold on
plot(ebsd('Forsterite'),ebsd('Forsterite').orientations.angle./degree);
hold off
ShadowWarrior
  • 180
  • 1
  • 12
  • Can you show an example? I am not sure how you want to contrast enhance something that its not an image – Ander Biguri May 16 '19 at 13:19
  • @AnderBiguri, I am using the MTEX toolbox, and [this](https://mtex-toolbox.github.io/files/doc/EBSDSpatialPlots.html) would be an example (look at "Visualizing arbitrary properties", I am trying to enhance the contrast of the black&white plot). Basically, is it possible to change contrast lively? – ShadowWarrior May 16 '19 at 13:35
  • 1
    It would be easier for us to provide an answer, if you could show us a source image, and a target image (adjusted manually, using some external tool), so that we could try to reproduce the same in MATLAB (or perhaps upload a screenshot of your figure, or the `.fig` file itself somewhere?). Looking at the link you provided, it appears that there are some semi-transparent patches, which you want to make opaque... In other words, it's a matter of replacing some colors with others (think of "find and replace", but with 3d vectors). Possibly related: https://stackoverflow.com/q/21576092. – Dev-iL May 16 '19 at 14:07
  • @Dev-iL, The image shows Band Contrast map from EBSD scanning, the data is in the BC column [here](https://raw.githubusercontent.com/mtex-toolbox/mtex/develop/data/EBSD/Forsterite.ctf) (with respect to X and Y coordinates). Each pixel is one BC point. – ShadowWarrior May 17 '19 at 12:45
  • @Dev-iL, I have added an example code in the OP, please have a look. – ShadowWarrior May 17 '19 at 12:59
  • You plot data, but don't have enough contrast? Plots have max contrast by design. Maybe you intend to change colors? What does your plot look like? – Cris Luengo May 21 '19 at 15:44

2 Answers2

0

Grab the image from the axes (if it is an image!)

im=getimage(rgb2gary(gca)); %it should already be gray, but matlab returns RGB anyway

and automatically adjust the contrast

im2=imadjust(im);

Set it again

imshow(im2,'Parent',gca); % or whatever other method you are using for display.
Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • The above code is not working, would it be possible for you to check. – ShadowWarrior May 17 '19 at 12:20
  • @ShadowWarrior this code works if the initial image is created with `imshow(i);colorbar; colormap gray`. You have not however told us how you create yours, so I can not check – Ander Biguri May 17 '19 at 12:28
  • The image shows Band Contrast map from EBSD scanning, the data is in the BC column [here](https://raw.githubusercontent.com/mtex-toolbox/mtex/develop/data/EBSD/Forsterite.ctf) (with respect to X and Y coordinates). Each pixel is one BC point. – ShadowWarrior May 17 '19 at 12:37
  • @ShadowWarrior its irrelevant what they are, the only relevant thing is what code you used to generate the plot you want to contrast enhance. Read the required [mcve] – Ander Biguri May 17 '19 at 12:45
  • I have added an example code in the OP, please have a look. – ShadowWarrior May 17 '19 at 13:00
  • @ShadowWarrior whoudl it be possible to show the image too? – Ander Biguri May 17 '19 at 13:05
  • [This](https://mtex-toolbox.github.io/files/doc/EBSDSpatialPlots_04.png) is the image after the first plot command, I need to contrast enhance it and then some other plots will be simply superimposed. – ShadowWarrior May 17 '19 at 13:17
  • @ShadowWarrior thats the one I used for testing yes. Can you not reuse it and call the plot function again? – Ander Biguri May 17 '19 at 13:37
  • You mean deleting "hold on" and plot im2? I thought imshow would take care of that but a blank image is showing up. – ShadowWarrior May 17 '19 at 13:56
0

enter image description hereOf what I see in the example, you want area with saturated colors on a background of "faint", milky colors. Try this solution of highlight by increased saturation.

rgb = imread('peppers.png');
% make under-saturated image
hsv = rgb2hsv(rgb);
hsv(:, :, 2) = hsv(:, :, 2)*0.2;
hsv(hsv > 1) = 1;  % Limit values
rgbFaint = uint8(255*hsv2rgb(hsv));
% make a mask of area to highlight
mask = false(size(rgb,1),size(rgb,2));
h = fspecial('disk',60) > 0;
mask(200:200+size(h,1)-1,200:200+size(h,2)-1) = h;
mask = repmat(mask,1,1,3);
% create image with highlight area
rgbHighlight = rgbFaint;
rgbHighlight(mask) = rgb(mask);
figure;
imshow(rgbHighlight)
Yuval Harpaz
  • 1,416
  • 1
  • 12
  • 16