Determine the axis range of the graph image
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I'm working on a small project on digitizing an image of a graph. I have a graph image as input and output as coordinate value (x,y) pairs of the graph in that image. Now I'm having a hard time determining the range of values of the axes. I want to use OCR to recognize the labels along the axes. But I don't know how to implement it. Can someone help me?? Here is an example of a graph image. I want to determine the min and max values of the x-axis (-20 and 20) and the y-axis (-1 and 6)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/777828/image.jpeg)
0 Commenti
Risposta accettata
yanqi liu
il 26 Ott 2021
sir,please check the follow code to get some information
clc; clear all; close all;
im = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/777828/image.jpeg');
bw = im2bw(im);
bw = ~bw;
bw2 = bwareaopen(bw, 1200);
bw(bw2) = 0;
bw = logical(bw);
bw3 = imclose(bw, strel('line', round(0.05*size(bw,1)), 90));
bw3 = imclose(bw3, strel('line', round(0.05*size(bw,2)), 0));
rs = sum(bw3, 2); cs = sum(bw3,1);
[~,ind1] = max(rs); [~,ind2] = max(cs);
y = 1:size(bw,1); x = 1:size(bw,2);
pt1 = [x(:) repmat(ind1,length(x), 1)];
pt2 = [repmat(ind2,length(y),1) y(:)];
bw3 = bwselect(bw3, [pt1(:,1); pt2(:,1)], [pt1(:,2); pt2(:,2)]);
bw(~bw3) = 0;
bw4 = imclose(bw, strel('line', round(0.05*size(bw,2)), 0));
bw41 = bwselect(bw4, [pt1(:,1)], [pt1(:,2)]);
bw42 = bwselect(bw4, [pt2(:,1)], [pt2(:,2)]);
bw42(bw41) = 0;
bw41 = logical(bw41); bw42 = logical(bw42);
[r1,c1] = find(bw41); [r2,c2] = find(bw42);
[~,ind1] = min(c1); [~,ind2] = max(c1);
[~,ind3] = min(r2); [~,ind4] = max(r2);
bw5 = bwselect(bw4, [c1(ind1) c1(ind2) c2(ind3) c2(ind4)], [r1(ind1) r1(ind2) r2(ind3) r2(ind4)]);
[L,num] = bwlabel(bw5);
stats = regionprops(L);
wh = 5;
bws = [];
figure; imshow(im);
for i = 1 : num
bwi = bw;
bwi(L~=i) = 0;
recti = stats(i).BoundingBox;
hold on; rectangle('Position', recti, 'EdgeColor', 'r', 'LineWidth', 2, 'LineStyle', '-');
recti = [recti(1:2)-wh recti(3:4)+2*wh];
bws{end+1} = imcrop(bwi, round(recti));
% use ocr or cnn
end
figure;
montage(bws, 'Size', [2 2], 'BackgroundColor', 'w', 'BorderSize', [3 3])
2 Commenti
yanqi liu
il 5 Dic 2021
yes,sir,if we can get the figure,may be use the handle to get data
of course,if just use image,the image may be use imresize to make it bigger,and use some interactive to get the effect value
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!