Display/highlight specific pixels of in image
לק"י
Hello guys,
A short code was written to allow me to gather data about cells masks that were clicked on in a figure.
I want to simoultaneously show all previous chosen cells with a color or other distinctive way to avoid picking twice the same cell.
Haven’t managed to find or think about easy and quick way to make it happen.
The cells masks are from time series stack that is being iterated for the amount of frames in the stack. All of this process is being iterated for the amount of cells I want to pick, which I specify in a variable before running the code.
the code:
stackfilename = ‘17.07.2024 aHER2 carrier W.T cd45low+cd4+lstrckr001 cellpose stack.tif’; %get the name of the
% time series stack of masks. These cellpose stacks are handing each cell a unique grayscale value
%ranging from 1 to the total amount of cells detected by cellpose. background (non-mask undetected cell pixels)
% is set to 0.
info = imfinfo(stackfilename); %Info function gets information of every single image of the image stack.
numberOfImages = length(info); %counting the length of info will give the amount of images in the stack.
cellnumber= 6; %Enter the desired amount of cells to be analysed.
pixelindexes={}; %Create a cell array that will hold each mouse click (mask choose) indexes.
pixelvalues={}; %Create a cell array that will hold each mask grayscale value.
for i = 1:cellnumber %The number of cells (number of main loops).
for j=1:numberOfImages %For each cell (main loop), a secondary loop will initiate for the amount…
%of frames in the cells masks stack (‘numberOfImages’).
crntimg = imread(stackfilename, j); % Read the current image
figure(1) %Create a figure
old = double(crntimg); %Turn the image from uint to double for later mathematical manipulation.
crntimgmax=double((max(max(crntimg)))); %Find the max grayscael value of the current frame…
%,equals total cell masks in the frame.
new = 10+(10*(old./crntimgmax)); %Manipulate the image matrix to allow dark tones
% (low values) to be shown with imshow command.
new(new==10)=0; %Set background values to 0 for the dark tones to be seen brighter.
imshow(new,[]) %Display image.
if i~=1 %If previous cells were chosen, start a loop that will…
%plot/show them on the new image that was created to avoid choosing the same cell twice.
hold on %Hold the image.
for k=1:(i-1)
imshow(crntimg==(pixelvalues{j,k}(1)),[]) %|||***This is where
% I can’t figure out how to SIMOULTANEOUSLY SHOW *ALL* OF THE PREVIOUSLY CHOSEN cell masks with
%a DISTINCTIVE COLOR or other way that will set them apart from the other yet unchosen cell masks.***|||
end
end
pixelindexes{j,i}= ginput(1); %Store pixel indexes.
pixelvalues{j,i}=impixel(crntimg,pixelindexes{j,i}(1,1),pixelindexes{j,i}(1,2)); %Store pixel values.
end
close (figure (1))
end
%Save the data
save(append(stackfilename, append…
( append(‘ ‘, strrep(string(datetime(now,’ConvertFrom’,’datenum’)),’:’,’-‘)),’ Worksapce data’)));
The part that I can’t seem to over come is the last for loop which should simoultaneously show all previous chosen masks with a distinctive color or any other way that will show the previously chosen cells distinctively. I tried my best to explain my self and provide with sufficient info. If anything else is needed or needs to be more clear please tell me.
Thanks,
Amit.לק"י
Hello guys,
A short code was written to allow me to gather data about cells masks that were clicked on in a figure.
I want to simoultaneously show all previous chosen cells with a color or other distinctive way to avoid picking twice the same cell.
Haven’t managed to find or think about easy and quick way to make it happen.
The cells masks are from time series stack that is being iterated for the amount of frames in the stack. All of this process is being iterated for the amount of cells I want to pick, which I specify in a variable before running the code.
the code:
stackfilename = ‘17.07.2024 aHER2 carrier W.T cd45low+cd4+lstrckr001 cellpose stack.tif’; %get the name of the
% time series stack of masks. These cellpose stacks are handing each cell a unique grayscale value
%ranging from 1 to the total amount of cells detected by cellpose. background (non-mask undetected cell pixels)
% is set to 0.
info = imfinfo(stackfilename); %Info function gets information of every single image of the image stack.
numberOfImages = length(info); %counting the length of info will give the amount of images in the stack.
cellnumber= 6; %Enter the desired amount of cells to be analysed.
pixelindexes={}; %Create a cell array that will hold each mouse click (mask choose) indexes.
pixelvalues={}; %Create a cell array that will hold each mask grayscale value.
for i = 1:cellnumber %The number of cells (number of main loops).
for j=1:numberOfImages %For each cell (main loop), a secondary loop will initiate for the amount…
%of frames in the cells masks stack (‘numberOfImages’).
crntimg = imread(stackfilename, j); % Read the current image
figure(1) %Create a figure
old = double(crntimg); %Turn the image from uint to double for later mathematical manipulation.
crntimgmax=double((max(max(crntimg)))); %Find the max grayscael value of the current frame…
%,equals total cell masks in the frame.
new = 10+(10*(old./crntimgmax)); %Manipulate the image matrix to allow dark tones
% (low values) to be shown with imshow command.
new(new==10)=0; %Set background values to 0 for the dark tones to be seen brighter.
imshow(new,[]) %Display image.
if i~=1 %If previous cells were chosen, start a loop that will…
%plot/show them on the new image that was created to avoid choosing the same cell twice.
hold on %Hold the image.
for k=1:(i-1)
imshow(crntimg==(pixelvalues{j,k}(1)),[]) %|||***This is where
% I can’t figure out how to SIMOULTANEOUSLY SHOW *ALL* OF THE PREVIOUSLY CHOSEN cell masks with
%a DISTINCTIVE COLOR or other way that will set them apart from the other yet unchosen cell masks.***|||
end
end
pixelindexes{j,i}= ginput(1); %Store pixel indexes.
pixelvalues{j,i}=impixel(crntimg,pixelindexes{j,i}(1,1),pixelindexes{j,i}(1,2)); %Store pixel values.
end
close (figure (1))
end
%Save the data
save(append(stackfilename, append…
( append(‘ ‘, strrep(string(datetime(now,’ConvertFrom’,’datenum’)),’:’,’-‘)),’ Worksapce data’)));
The part that I can’t seem to over come is the last for loop which should simoultaneously show all previous chosen masks with a distinctive color or any other way that will show the previously chosen cells distinctively. I tried my best to explain my self and provide with sufficient info. If anything else is needed or needs to be more clear please tell me.
Thanks,
Amit. לק"י
Hello guys,
A short code was written to allow me to gather data about cells masks that were clicked on in a figure.
I want to simoultaneously show all previous chosen cells with a color or other distinctive way to avoid picking twice the same cell.
Haven’t managed to find or think about easy and quick way to make it happen.
The cells masks are from time series stack that is being iterated for the amount of frames in the stack. All of this process is being iterated for the amount of cells I want to pick, which I specify in a variable before running the code.
the code:
stackfilename = ‘17.07.2024 aHER2 carrier W.T cd45low+cd4+lstrckr001 cellpose stack.tif’; %get the name of the
% time series stack of masks. These cellpose stacks are handing each cell a unique grayscale value
%ranging from 1 to the total amount of cells detected by cellpose. background (non-mask undetected cell pixels)
% is set to 0.
info = imfinfo(stackfilename); %Info function gets information of every single image of the image stack.
numberOfImages = length(info); %counting the length of info will give the amount of images in the stack.
cellnumber= 6; %Enter the desired amount of cells to be analysed.
pixelindexes={}; %Create a cell array that will hold each mouse click (mask choose) indexes.
pixelvalues={}; %Create a cell array that will hold each mask grayscale value.
for i = 1:cellnumber %The number of cells (number of main loops).
for j=1:numberOfImages %For each cell (main loop), a secondary loop will initiate for the amount…
%of frames in the cells masks stack (‘numberOfImages’).
crntimg = imread(stackfilename, j); % Read the current image
figure(1) %Create a figure
old = double(crntimg); %Turn the image from uint to double for later mathematical manipulation.
crntimgmax=double((max(max(crntimg)))); %Find the max grayscael value of the current frame…
%,equals total cell masks in the frame.
new = 10+(10*(old./crntimgmax)); %Manipulate the image matrix to allow dark tones
% (low values) to be shown with imshow command.
new(new==10)=0; %Set background values to 0 for the dark tones to be seen brighter.
imshow(new,[]) %Display image.
if i~=1 %If previous cells were chosen, start a loop that will…
%plot/show them on the new image that was created to avoid choosing the same cell twice.
hold on %Hold the image.
for k=1:(i-1)
imshow(crntimg==(pixelvalues{j,k}(1)),[]) %|||***This is where
% I can’t figure out how to SIMOULTANEOUSLY SHOW *ALL* OF THE PREVIOUSLY CHOSEN cell masks with
%a DISTINCTIVE COLOR or other way that will set them apart from the other yet unchosen cell masks.***|||
end
end
pixelindexes{j,i}= ginput(1); %Store pixel indexes.
pixelvalues{j,i}=impixel(crntimg,pixelindexes{j,i}(1,1),pixelindexes{j,i}(1,2)); %Store pixel values.
end
close (figure (1))
end
%Save the data
save(append(stackfilename, append…
( append(‘ ‘, strrep(string(datetime(now,’ConvertFrom’,’datenum’)),’:’,’-‘)),’ Worksapce data’)));
The part that I can’t seem to over come is the last for loop which should simoultaneously show all previous chosen masks with a distinctive color or any other way that will show the previously chosen cells distinctively. I tried my best to explain my self and provide with sufficient info. If anything else is needed or needs to be more clear please tell me.
Thanks,
Amit. matrix manipulation, digital image processing, imshow, overlay images/pixels, multiple imshow MATLAB Answers — New Questions