how to change the color of one pixel in a binary image ?
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
i want to change the color of one pixel of a binary image.for example change a white pixel to red.would you pleaz help me?
0 Kommentare
Antworten (2)
Image Analyst
am 27 Dez. 2015
You can convert it to a color image and then set the pixel to red, like harjeet did. Of course I hope you know that the RGB image is no longer a binary image, so don't use that in any further processing, like pass it to regionprops() or bwconncomp() or something.
An alternative is to just plot a red dot over the pixel.
imshow(binaryImage); % Display it.
% Plot a red dot at row 30, column 173
hold on;
plot(173, 30, 'r.', 'MarkerSize', 10);
Make the marker size whatever you want. This does not create a new color image and does not change the binary image, it just plots a red dot in the overlay above the image. The two solutions so far will both make a red pixel on the displayed image at the designated position, but they do it in different ways. Pick whichever solution does it in the way you want most.
0 Kommentare
harjeet singh
am 27 Dez. 2015
hello fariba you may use this code
clear all
close all
clc
a=100;
img(1:a,1:a)=0;
img=logical(img);
pixel_val=[50 50;50 10;20 30];
for i=1:size(pixel_val)
rgb_img(pixel_val(i,1),pixel_val(i,2),:)=[255 0 0];
end
figure(1)
imshow(rgb_img);
drawnow
2 Kommentare
Anuruddha Jayasuriya
am 19 Jul. 2018
Hi, harjeet singh. In your code, can you tell what is the purpose of defining a=100. Also what does img=logical(img) do in this code.
Thanks!
Dzung Nguyen
am 20 Mär. 2019
Bearbeitet: Dzung Nguyen
am 20 Mär. 2019
a = 100 is just there to set the dimension of img later in the next line.
img=logical(img) --> see https://www.mathworks.com/help/matlab/ref/logical.html
Siehe auch
Kategorien
Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!