![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/445243/image.png)
How to make scatter size the same as pixel size
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
qi lu
el 3 de Dic. de 2020
Respondida: Image Analyst
el 4 de Dic. de 2020
I plot a figure by 'imagesc'.
And I want to replace the pixels on the diagonal line with white color.
I use 'scatter(1:100,1:100,30,'w','s','fill')'. But it is difficult to make scatter size the same as pixel size.
Is there any solution or workaround?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/442543/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/442548/image.jpeg)
0 comentarios
Respuesta aceptada
Image Analyst
el 4 de Dic. de 2020
Try this demo:
% Demo by Image Analyst to burn red into some pixels of an indexed image.
% First we need to convert the indexed image to RGB then we burn red in.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
fprintf('Beginning to run %s.m ...\n', mfilename);
%-----------------------------------------------------------------------------------------------------------------------------------
% Read in image.
folder = fileparts(which('kids.tif')); % Determine where demo folder is (works with all versions).
baseFileName = 'kids.tif';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
% It's not an RGB image! It's an indexed image, so read in the indexed image...
[indexedImage, storedColorMap] = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(indexedImage)
% Display the indexed image with no colormap
subplot(2, 2, 1);
imshow(indexedImage, []);
colorbar;
axis('on', 'image');
caption = sprintf('Indexed Image with no colormap applied: "%s"', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
hFig1 = gcf;
hFig1.Units = 'Normalized';
hFig1.WindowState = 'maximized';
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
hFig1.Name = 'Demo by Image Analyst';
% Display the indexed image with the colormap it was stored with.
subplot(2, 2, 2);
imshow(indexedImage, 'Colormap', storedColorMap);
colorbar;
axis('on', 'image');
caption = sprintf('Image with the stored colormap applied to it');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Create an RGB image
rgbImage = ind2rgb(indexedImage, storedColorMap);
% Display the indexed image with the colormap it was stored with.
subplot(2, 2, 3);
imshow(indexedImage, 'Colormap', storedColorMap);
axis('on', 'image');
caption = sprintf('RGB image from applying colormap to indexed image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
%-----------------------------------------------------------------------------------
% Make the mask pure red, i.e. (255, 0, 0) at some points, listed in arrays x and y.
fprintf('Making some points red in the RGB image...\n');
numPoints = 100;
x = randi([1, columns], numPoints);
y = randi([1, rows], numPoints);
for k = 1 : numel(x)
row = y(k);
column = x(k);
rgbImage(row, column, :) = uint8([255, 0, 0]);
end
% Display the initial mask image.
subplot(2, 2, 4);
imshow(rgbImage, []);
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
axis('on', 'image');
title('With red pixels burned in', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
fprintf('Done running %s.m ...\n', mfilename);
msgbox('Done!');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/445243/image.png)
Note that RGB images have no colormap or color bar because it does not apply in that situation. Note that there appears to be about 64 colors in the colormap and the indexed image has values ranging from 0 to 64 or so as you can see by looking at the colorbars beside the upper two images. I used [] in imshow() to scale the image to 0-255 so you could see it, otherwise the image would range from 0-64 and look pretty dark. There are no values above 64 so the colorbar on the upper right just has black there - there are no values between 65 and 255 to apply the color mapping to.
0 comentarios
Más respuestas (1)
Image Analyst
el 3 de Dic. de 2020
The pixel size depends on the size of your figure. If you resize your figure then the pixel size will change. So I think the best you can do, if you're overlaying a scatterplot over an image, is to just adjust the size (third argument to scatter) manually to be a reasonable size for the figure sizes you expect to have.
Otherwise you can simply burn the pixel directly into the image with some color instead of using scatter, which puts markers into the overlay.
Ver también
Categorías
Más información sobre Blue en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!