fixed color scale with volshow
0 Comments
Answers (3)
Hi @Lara ,
To achieve a consistent color scale across all frames in your volumetric visualization, you can follow these steps:
1. Define a Fixed Color Scale:You need to set fixed limits for the color scale (CLim) that applies uniformly to all frames. This involves determining the minimum and maximum hemoglobin concentration values across all frames before visualization.
2. Update Normalization Logic:Instead of normalizing each frame individually based on its own min-max values, normalize all frames based on the global minimum and maximum values determined earlier.
3. Implementation Example: Here’s how you can adjust your code to implement a fixed color scale across all frames:
% Step 1: Determine global min and max across all volumes all_data = cat(4, compressed_hbt_all{:}); globalMin = min(all_data(:)); % Compute the global minimum globalMax = max(all_data(:)); % Compute the global maximum
% Step 2: Normalize using global min and max normalized_hbt_all = cell(1, num_frames); for i = 1:num_frames vol_i = compressed_hbt_all{i}; norm_vol = (vol_i - globalMin) / (globalMax - globalMin); norm_vol = min(max(norm_vol, 0), 1); % Clip between 0 and 1 normalized_hbt_all{i} = norm_vol; end
% Step 3: Visualization with fixed CLim cmap = jet(256); alphaMap = (linspace(0, 0.7, 256).^2); alphaMap(1) = 0;
fig = uifigure(); uip = uipanel(fig, Units="normalized", Position=[0 0 .90 1], BorderType="none"); viewer = viewer3d(uip); viewer.BackgroundColor = [1 1 1];
for i = 1:num_frames vol = volshow(normalized_hbt_all{i}, 'Colormap', cmap, 'Alphamap', alphaMap, Parent=viewer); ax = axes(fig, Visible="off"); ax.Colormap = cmap; ax.CLim = [0, 1]; % Set fixed color limits cb = colorbar(ax,"Units","normalized","Color",[.8 .8 .8]); cb.Position(1) = 0.90; cb.Label.String = 'HbT concentration [M]'; cb.Label.FontSize = 20; cb.Label.Rotation = 270; cb.Label.VerticalAlignment = 'bottom';
frameLabel.Text = sprintf('Time: %d s', i); drawnow; frame = getframe(fig); writeVideo(writerObj, frame); end close(writerObj);
Here are some additional insights that can help further
Dynamic Range Consideration: By setting `globalMin` and `globalMax` based on the entire dataset rather than per-frame values, you ensure that the same color mapping applies consistently throughout your visualization.
Colormap Selection: The choice of colormap (`jet` in this case) can significantly impact the interpretation of data. Consider using perceptually uniform colormaps like `parula` or `cmocean`, which may provide better visual clarity.
By following these guidelines, you should be able to maintain a consistent and accurate representation of hemoglobin levels across your volumetric visualizations.
Hope this helps.
0 Comments
I didn’t see it in your code, but I assume you are already setting the volshow colormap to match the cmap you used for the colorbar.
Have you tried specifying the DisplayRange property for volshow and setting it to [globalMin, globalMin]?
0 Comments
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!