Hi @Moustafa,
I did read your comments and after some research, I implemented the example code in MATLAB. Hope this is what you are looking for if I interpret your comments correctly.
% Step 1: Read the Color Map Image colorMapImg = imread('/MATLAB Drive/Color map.jpg');
% Step 2: Convert Image to Grayscale (if necessary) grayMap = rgb2gray(colorMapImg); % Convert to grayscale
% Step 3: Create X and Y coordinates based on image dimensions [rows, cols] = size(grayMap); [x, y] = meshgrid(1:cols, 1:rows);
% Step 4: Normalize grayscale values to match contour levels normalizedGrayMap = double(grayMap) / 255; % Normalize to [0, 1]
% Step 5: Define Contour Levels Based on Color Bar Values % Assuming color bar ranges from minValue to maxValue minValue = 0; % Adjust according to your color bar maxValue = 1; % Adjust according to your color bar numContours = 10; % Define number of contour levels contourLevels = linspace(minValue, maxValue, numContours);
% Step 6: Generate Contours figure; contour(x, y, normalizedGrayMap, contourLevels); colorbar; % Display color bar for reference
% Step 7: Add Titles and Labels title('Contour Map from Color Map'); xlabel('X-axis'); ylabel('Y-axis');
Please see attached.


So, let me explain what the above code is doing step by step.
Reading and Processing: The `imread` function loads the image. If your color map is not grayscale, converting it helps simplify contour generation.
Creating Meshgrid: This sets up a grid for plotting the contours.
Normalization: The grayscale values are normalized between 0 and 1 for contouring.
Contour Levels: You can adjust `minValue`, `maxValue`, and `numContours` based on your specific color bar scale.
Plotting Contours: The `contour` function generates contour lines based on your specified levels.
Further tips below to enhance code if you prefer
Color Mapping: If your original image has specific RGB values corresponding to certain data points, you may need a more complex mapping function to convert those RGB values directly into numeric data values.
Boundary Coordinates: If you have specific boundary coordinates, you might need to adjust your meshgrid accordingly or crop your image before processing.
Visualization: Always check your output visually to ensure that contours represent the expected data accurately.
By following these steps and using the provided code as a foundation, you should be able to successfully convert your color map into a contour map in MATLAB while maintaining alignment with your original color bar values.
Hopefully this helps.